The Taylor series expansion for cos(x) is: cos(x)=1-x^2/2!+x^4/4!-x^6/6!+… =
∞ ∑ (-1)^n/(2n)n!(x^2n) n=0where x is in radians. Write a MATLAB program that determines cos (x) usingthe Taylor series expansion. The program asks the user to type a value for anangle in degrees. Then the program uses a loop for adding the terms of theTaylor series. If an is the nth term in the series, then the sum Sn of the n termsis sn = sn-1 + an . In each pass calculate the estimated error E given byE = abs(Sn-Sn-1/Sn-1)· Stop adding terms when E<=0.000001. The program displays the value of cos(x). Use the program for calculating:(a) cos(35°) (b) sin(125°)Compare the values with those obtained by using a calculator.
so far i have the following but it is not working.
A = input('Enter the value for an angle in degrees = ');n=1; an = 1; Sn = Sn-1+an; while E <= 0.000001 an = cos(35)/factorial(n); Sn = Sn-1 + an n = n+1;endif n <= 0.000001 disp('stop')fprintf('Sn - Sn-1/Sn(%f) = %f', cos,Sn)end
Best Answer