Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions