Question: Numerical Methods & MatLab! Please show code and outputs clearly as well as an explaination. Thank you in advance!!! 3 Taylor Series in MATLAB (25
3 Taylor Series in MATLAB (25 points) The function f(x)=cos(x) can be represented in a Taylor series as follows (where x is in radians): cos(x)=12!x2+4!x46!x6+=n=0(2n)!(1)nx2n=n=0an Write a function file cosTaylor.m that computes the value of cos x using this Taylor series. The function takes the input x in radians and return cos(x) approximation as output. \[ \text { function cos_ } x=\operatorname{cosTaylor}(x) \] The program should use a loop structure to add each term of the summation. If an is the nth term in the series, the sum Sn of the n terms is Sn=Sn1+an. In each loop iteration calculate the estimated error E given by: E=Sn1SnSn1 Repeat the loop until E is smaller than 0.00001 OR the number of terms that have already been added is not greater than 30 . The function should print on screen the number of terms used in the summation when the loop ends. - Report the MATLAB script file and the output of following function calls: cosTaylor(pi/4), cosTaylor (17pi/5), and cosTaylor (22) - Compare the outputs against the cos ( ) function which is predefined in MATLAB: cos(pi/4), cos(17pi/5), and cos(22) Hint: Use while-end loop. You may use break keyword if needed and the factorial () function to calculate the denominator (2n)! in an
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
