Write a Matlab function called sine_Taylor that inputs a positive integer n, a n
ID: 2085405 • Letter: W
Question
Write a Matlab function called sine_Taylor that inputs a positive integer n, a number x, and outputs the nth Taylor polynomial of the sine function. Compute the absolute and error for n = 1: 10 at x = 1, obtained by comparing the output of your function to that of Matlab's built in sine function. Type on the Matlab console format long, then compute the previous error. Repeat the operation by typing format short. Comment on the result (quantify the difference) Make three plots of the absolute error: loglog, semilogx, and semilogy. The axes should be properly labeled. If you make plots of the logarithms of the data you will not receive full credit. Decide which of the three plots gives you a linear error decay. Then use the points n = 5: 8, and the polyfit function to obtain the form of the error Write down the theoretical error as a function of n. Compare the result to your actual error What happened to the points n = 9, 10 on your plots?Explanation / Answer
2.) (a) The matlab code is clear clc n = input('Enter number of iiterations (n): ' ); x = pi/3; y = zeros(1,n); for i = 1:n y(i) = (-1)^i*x^(2*i+1)/factorial(2*i+1); end SINx = sum(y);
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.