Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB question. please explain the step as well. Thanks 5. Use the Taylor serie

ID: 3773929 • Letter: M

Question

MATLAB question. please explain the step as well. Thanks

5. Use the Taylor series to compute cosx to a specified degree of accuracy, indicated by the user in the form of number of decimal places. If p places have been specified, then the error will be small enough when the first dropped term is less than 5 x 10-(p+1). For instance, if you want cos x (for some specified x) accurate to 3 decimal places, then add terms of the Taylor series until the next term is smaller than 5 x 10 4. Don't include this term; the sum of all the previous terms is the answer to the desired accuracy. Obviously, your solution may not use MATLAB's cos function!

Explanation / Answer

% Ask user for values cos angle, nth term
x=input('Please enter a value for cos angle: '); %cos angle
% converted angle into radian
x_rad=x*pi/180;
n=input('Please enter a value for n: '); %nth term

sum=0;
for k=1:n
   initial = (-1)^(k-1);
   numerator = x_rad^(2*(k-1));
denominator = factorial(2*(k-1));

% sum of all the terms

sum=sum+total;
end
fprintf('cos(%d)=%6.6f ',x,sum);