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

Problem 5 xx The Taylor series expansion for sin(x) is sin(x) = x -H + E-E+ = o

ID: 3168370 • Letter: P

Question

Problem 5 xx The Taylor series expansion for sin(x) is sin(x) = x -H + E-E+ = o E- (-1) . 2n +1 no (2n+1)! !57 where x is in radians. Write a MATLAB program that determines sin(x) using the Taylor series expansion. The program asks the user to type a value for an angle in degrees. Then the program uses a while loop for adding the terms of the Taylor series. If an n is the nth term in the series, then the sum Sne of the n terms is S, =Sau + E. In each pass calculate the estimated error E given by E = sner said. Stop adding terms when E 1E-8. The program displays the - Sold value of sin(s). Use the program for calculating sin(45) and sin(195) Show the results as: The sing of L is providing an error equal to L. Use scientific notation with 2 decimal places Problem 6 Write a MATLAB program for problem 5 using a for loop. Run the program for 5, 10, and 15 steps. Display the error at the end of the calculations.

Explanation / Answer

clc;
clear all;
x=deg2rad(input('x='))
s_old=0;
% for n=10;
n=0;
err=0.1;
while(err>1e-8)
s_new=s_old+((-1)^n/factorial(2*n+1))*x^(2*n+1);
err=abs((s_new-s_old)/s_old);
s_old=s_new;
n=n+1;
end
fprintf('The sin of %d degre is %f provinding an error is %e',x,s_new,err)

Answer

x=45

x =

0.7854

The sin of 7.853982e-001 degre is 0.707107 provinding an error is 2.485123e-009

x=195

x =

3.4034

The sin of 3.403392e+000 degre is -0.258819 provinding an error is 2.561443e-010;

clc;
clear all;
x=deg2rad(input('x='));
n=input('n=');
s_old=0;

for i=1:n
s_new=s_old+((-1)^(i-1)/factorial(2*(i-1)+1))*x^(2*(i-1)+1);
err=abs((s_new-s_old)/s_old);
s_old=s_new;
end

s_new
err

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote