A series expansion for sin(x) is given by sin(x) = x – x^3/3! + x^5/5! – x^7/7! + … a) Write a Matlab script to calculate sin (pi/3) using this series expansion. Ensure that the script will add terms one at a time until the numerical result is accurate to 4 significant figures. b) Plot the exact analytical form of sin(x) for 0
Expert Answer
format short
function approx = Sine(val)
x = val;
k = 1;
i = 3;
count = 3;
while(abs( ((sin(val)))- x) > 0.00001)
x = x + ( (-1)^k *(val)^i )/factorial(i);
k = k+1;
i = 2*count – 1;
count = count + 1;
end
approx = x;
end
approx =Sine(0.33*pi);
fprintf(“Approximate value of Sine for 0.3PI is: %.4fn”,approx);
approx =Sine(pi/6);
fprintf(“Approximate value of Sine for (PI/6) is: %.4fn”,approx);
============================================================
See Output , You can verify Sine values