Question: MATLAB: Write an M-file for cos(x) so that it computes and and prints out the values of x. The cosine function can be evaluated by
MATLAB: Write an M-file for cos(x) so that it computes and and prints out the values of x.
The cosine function can be evaluated by the following infinite series: cos x = 1 - x^2/2! + x^4/4! - x^5/6! + ....Write an M-file to implement this formula so that it computes and prints out the values of cos x as each term in the series is added. Employ the library function for the cosine in your Matlab to determine the true value. In other words, compute and print in sequence the values for cos x = 1; cosx = 1 - x^2/2!; up to the order term n of your choosing. For each of the preceding, compute and cos x =1 - x^2/2! + x^4/4! display percent relative error as % error = (true-series approximation/true times 100%. Have the program print out the series approximation and the error at each step
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
