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

Answer in MATLAB please. How many terms are required in (iii) to reduce the rela

ID: 3823147 • Letter: A

Question

Answer in MATLAB please.

How many terms are required in (iii) to reduce the relative error to less than 1%? 0.00001%? Assume that the relative error (percent) is defined as: % Error = |(S_t - S_n)/S_t| times 100 S_t = sin x, S_t = sigma^infinity_n = 0 (-1)^n x^2n + 1/(2n + 1)! where S_t and S_n are the true and numerical solutions, respectively. The "numerical solution will come from the summation of terms while the true solution can be obtained using the built-in MATLAB function for sin(x). Each iteration through the loop, create a formatted output that shows (1) the iteration number, (2) the number of terms in the series and (3) the percent error between the obtained values. The output printed during the loop should be done so that a new line is created each time a new output is printed. When the loop has completed, display the result, the final percent error, and the number of terms using a single command. Save the percent error per iteration and plot % error vs. iteration when the loop has completed.

Explanation / Answer

Ihave printed the error percentages.

Please provide a sample of output which is required and also specify the range and value of x that should be considered.

x = pi/8;
n = [0:0.1:1];

st = sin(x);

for i=0:length(n)
  
   n1 = [0:1:i];
   sn1 = ((-1).^n1).*(x.^(2.*n1 + 1))./(factorial(2.*n1 + 1));
   sn = sum(sn1);
  
   error = abs(((st-sn)/st)*100);
  
   fprintf('Error : %i ',error);
end

Error : 2.61722                                                                                                                                                                 

Error : 0.0202621                                                                                                                                                               

Error : 7.45108e-05                                                                                                                                                             

Error : 1.59708e-07                                                                                                                                                             

Error : 2.23983e-10                                                                                                                                                             

Error : 2.32092e-13                                                                                                                                                             

Error : 1.45058e-14                                                                                                                                                             

Error : 1.45058e-14                                                                                                                                                             

Error : 1.45058e-14                                                                                                                                                             

Error : 1.45058e-14                                                                                                                                                             

Error : 1.45058e-14                                                                                                                                                             

Error : 1.45058e-14