Home /
Expert Answers /
Computer Science /
the-cosine-function-can-be-approximated-by-a-maclaurin-series-expansion-as-cos-x-1-frac-x-pa300
(Solved):
The cosine function can be approximated by a Maclaurin series expansion as: \[ \cos (x)=1-\frac{x^ ...
The cosine function can be approximated by a Maclaurin series expansion as: \[ \cos (x)=1-\frac{x^{2}}{2 !}+\frac{x^{4}}{4 !}-\frac{x^{6}}{6 !}+\frac{x^{8}}{8 !}-\cdots \] where \( x \) is in radians. This expression can be used to approximate the cosine of \( x \) with increasing accuracy as terms are added to the summation. Code has already been provided to define a function named maclaurincosine that accepts input values into the following two variables. - The variable \( \mathrm{x} \) accepts a value for \( x \) (in radians) for the series approximation of \( \cos (x) \). - The variable \( N \) accepts an integer specifying the number of series terms, \( N \), to use in the approximation. Add code to the function to generate the following two output variables. 1. Generate a column vector of the first \( N \) series terms and assign this vector to the variable terms. 2. Generate a column vector of the first \( N \) series summations. The first summation is 1 , second is \( 1-x^{2} / 2 ! \), third is \( 1-x^{2} / 2 !+x^{4} / 4 ! \), and so on. Assign this vector to the output variable seriessums. The first two tests check the results for the second and third series terms respectively to aid in your debugging process. You can also check these values with a hand calculation. Note the values of \( x \) and \( \mathrm{N} \) are defined as inputs to the function. Do not overwrite these values in your code. Be sure to assign values to each of the function output variables. Feel free to use the built-in factorial function to calculate the denominators of the terms. Function 0 function series_sum = maclaurincosine \( (\mathrm{x}, \mathrm{N}) \) \%Enter the commands for your function here. Code to call your function ? C Reset