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

The Maclaurin series expansion for sin(x) is given by sin(x) = sigma^infinity_k

ID: 3885717 • Letter: T

Question

The Maclaurin series expansion for sin(x) is given by sin(x) = sigma^infinity_k = 0 (-1)^k/(2k + 1)! x^2k + 1 = x - x^3/3! + x^5/5!- ... Implement the expansion as a MATLAB function and approximate sin(2 pi /3). The value x and the stopping criteria (epsilon_s) should be inputs to the function. Your function should terminate when the approximate percent relative error falls below a stopping criteria corresponding to 4 significant digits. (Note rightarrow type "format long" into the command window before running your code).

Explanation / Answer

program:--

function sin_in_MaclaurinSeries(x,stop) %x is input for sin value and stop is for number of terms
    truevalue=0.86602540378; %sin(2pi/3) original value
    approxvalue=0; %initial approximate value
    term=1;   %initially term is 1, term indicates nthterm in the series
    p_error=100; %percentage relative error initially 100
    while p_error>stop %loop repeats untill stop
      fprintf('error %f ',p_error);
      if mod(term,2)==1 % check for current term is odd or even in our series odd indicates + and eben indicates - infront of terms
        approxvalue=approxvalue+power(x,2*term-1)/factorial(2*term-1); %if term is odd then add to sum
      else
        approxvalue=approxvalue-power(x,2*term-1)/factorial(2*term-1); %if term is even then substract from sum
      end
      term=term+1; % in each iteration increment the term by 1
      r_error=abs(truevalue-approxvalue)/truevalue;% relative error
      p_error=r_error*100; %percentage relative error
    end
    fprintf('Sin(2pi/3)=');
    disp(approxvalue); %display the result
end

output:--

>> sin_in_MaclaurinSeries(2*pi/3,0.1245)
error 100.000000
error 141.839915
error 34.964847
error 3.812776
error 0.237169
Sin(2pi/3)=   0.866108266762347

>> sin_in_MaclaurinSeries(2*pi/3,0.0245)
error 100.000000
error 141.839915
error 34.964847
error 3.812776
error 0.237169
Sin(2pi/3)=   0.866108266762347

>> sin_in_MaclaurinSeries(2*pi/3,0.0005)
error 100.000000
error 141.839915
error 34.964847
error 3.812776
error 0.237169
error 0.009568
Sin(2pi/3)=   0.866023057063188

>>

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