For this week\'s ICA, we will get some extra practice working with series type p
ID: 3907278 • Letter: F
Question
For this week's ICA, we will get some extra practice working with series type problems to help prepare you for the Final Exam. The series you will be looking at this week is presented below: x2n +1 = ?--+ + = sin(x) 3! 5! 7! The value of x must be entered in radians for this series. Write a Matlab script file which determines the value of sin(x) using the given Taylor series expansion. The program must allow the user to input a value for an angle in degrees. This value should be converted to radians for use in the series. The program must use a loop to add terms to the series. If an is the nth term in the series, then the sum S of the n terms is Sn Sn-+ an. In each pass, you must calculate the estimated error, E, given by the following equation Sn -Sn-1 Stop adding terms to the series when E s 0.000001. Finally, the program should use an fprintf command to display the following to the user: The estimate for sin(x) is x.xxxx and the actual value of sin(X) is x.xxxxxx.:' Be sure to show the correct number of decimal places specified. Use the built-in Matlab function sin() to display the actual value. Compare your estimated values of sin with the actual values to determine the accuracy of your estimates. t is recommended that you develop a flowchart on paper, like the one you were given in the previous ICA, to help develop your solution before typing any code using Matlab. It may also be beneficial to practice writing the code itself on paper or in Microsoft word and then transferring it to Matlab to test it out in order to better prepare you for the Final Exam.Explanation / Answer
Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you
angleDeg = input('Enter angle in degrees: ');
x = angleDeg * pi / 180; %convert from degrees to radians
S = 0;
E = 1;
n = 0;
while E > 1E-6
term = (-1)^(n) * x^(2*n+1) / factorial(2*n+1);
S1 = S + term;
if S ~= 0
E = abs((S1-S)/S);
end
S = S1;
n = n + 1;
end
fprintf("The estimate of sin(%d) is %.6f and the actual value is %.6f ", angleDeg, S, sin(x));
=====
output
====
Enter angle in degrees: > 45
The estimate of sin(45) is 0.707107 and the actual value is 0.707107
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.