The Taylor series expansion for cos (x) is: cos (x) = 1 - x^2/2! + x^4/4! - x^6/
ID: 3821710 • Letter: T
Question
The Taylor series expansion for cos (x) is: cos (x) = 1 - x^2/2! + x^4/4! - x^6/6! + = sigma^infinity _n = 0 (- 1)^n/(2n) ! x^2n where X is m radians. Write a MATLAB program that determines cos (x) using the Taylor series expansion. The program should ask the user to input the angle in degrees If a_n is the nth term in the series, then the sum S_n of the n terms is S-n = S_n - 1 + a_n. The program should calculate the expansion until the error given by E = |S_n - S_n - 1/S_n - 1| is less than 0.000001. Use an fprintf command to output the value. The output should read "The cosine of XXX degrees is XXX".Explanation / Answer
A = input('Enter the value for an angle in degrees = '); x = A * pi / 180; % Convert the input to radians n = 0; % First value of n an = 1; % First term in the series Sn = an; % First sum of the terms E = inf; % Some arbitrary big value while E > 0.000001 % While the estimated error is BIGGER n = n + 1; % Increment n an = ((-1)^n/factorial(2n))*x^2n; % Next term in the series E = abs(an/Sn); % Estimated error Sn = Sn-1 + an; % Add nth term into the sum end fprintf('The cosine of %f degrees is %f',A,Sn)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.