Question: Problem 2 (Relative error using real value) The Taylor series expansion for cos(x) is: cos(x)=12!x2+4!x46!x6+=n=0(2n)!(1)nx2n where x is in radians. Write a MATLAB program that
Problem 2 (Relative error using real value) The Taylor series expansion for cos(x) is: cos(x)=12!x2+4!x46!x6+=n=0(2n)!(1)nx2n where x is in radians. Write a MATLAB program that determines cos(x) using the Taylor series expansion. The program asks the user to type a value for an angle in degrees. Use a while-end loop to compute the value of cos(x). Stop loop when the error is less than 0.001. The error is defined as the difference between your estimation and the real value of cos(x). In each pass calculate the error. (Hint: You need to give an initial value of error which is greater than 0.001 to make you loop start. You also need to increase your n by 1 for each iteration in your loop, i.e: n=n+1 ) a. Stop adding terms when error is less than 0.001. b. How many iterations do you need to run to make the error less than 0.001. c. Plot the value of cos(x) calculated by your code as a function of iteration number n. d. Plot the value of relative error calculated by your code as a function of iteration number n
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
