The Taylor series expansion for sin(x) is where x is in radians. Write a MATLAB
ID: 3645458 • Letter: T
Question
The Taylor series expansion for sin(x) is 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 loop for adding the terms of the Taylor series. If an is the nth term in the series, then the sum Sn of the n terms is Sn = Sn -1 + an. In each pass calculate the estimated error E given by E=|Sn - Sn - 1/Sn - 1|. Stop adding terms when E 0.000001. The program displays the value of sin(x). Use the program for calculating: sin(45 degree) sin(195 degree). Compare the values with those obtained by using a calculator.Explanation / Answer
a=input('enter angle in degrees'); theta=a*pi/180; E=1; i=1; sum=0; sum1=0; while(E>=0.000001) sum1=sum; sum=sum1+(-1)^(i+1)*(theta ^(2*i-1))/factorial(2*i-1); E=abs((sum-sum1)/sum1); if(i>=10) exit(1); end end disp(sum)
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.