Question: The function y = c o s x can be approximated by the polynomial: = 1 - x 2 4 + x 4 2 4

The function y=cosx can be approximated by the polynomial: =1-x24+x424-x6720+x1440320+x103628800, provided that x is reasonably close to o. We wish to write a function M file to approximate the function cosx, but we need to take advantage of the periodicity of cosx to reduce the errors.
a) Write a function M file called cosApprox(x) to do the following:
i) Test to see that x is positive, and if it is not, stop the function.
ii) While x is still greater than 2, subtract 2 from x.
iii) After this is done, x should be between o and 2. Use the above degree 8 polynomial to estimate cosx.
b) Write a program M file that does the following.
i) Set up a vector of x values from o to 2, in steps of 0.1.
ii) Use a For-Loop to go through the vector of x-values
iii)At each x-value call your function cosApprox on that x-value. Call the Matlab function cosx and subtract the two to find the error. Divide the actual value of cosx and multiply by 100 to find the percentage error. Display both the x-value and the percentage error. (Note that percentage error is given by:
estimated-actualactual100%. Sometimes this will be positive and sometimes it will be negative and this is expected.
iv) Plot the percentage error on a graph
 The function y=cosx can be approximated by the polynomial: =1-x24+x424-x6720+x1440320+x103628800, provided

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!