The infinite Maclaurin series to calculate the sine of an an

The infinite Maclaurin series to calculate the sine of an angle in radians is: sin (x) = x - x^3/3! + x^5/5! - x^7/7! + x^9/9! -... Write a function, named sine, to calculate the sine of an angle using the above Maclaurin series. Use the fact function created in problem 1 in the sine function. Iterate the terms until the difference between the previous term and the current term is less than 10^-5.

Solution

here sin(x) is an odd function (i.e sin(-x) = -sin (x))

function out = approxSin(x,n)

out = 0;

for k=0:n-1;

out = out +(-1)^k * x^(2*k+1) / factorial (2*k+1);

end

y = sin(x);

percenterror = [abs{(out-y)/y}]*100;

here n= number of terms for the approximation series

the difference should be less than 0.00001

function out = approxsin2(x)

y = sin(x)

b= ( <0.00001*y)+y

c= -(b-y)+y

k= 0, p=0

while c<p<b

k=k+1

p= x+(-1)^k*x^(2*k+1)/factorial(2*k+1)

end.

 The infinite Maclaurin series to calculate the sine of an angle in radians is: sin (x) = x - x^3/3! + x^5/5! - x^7/7! + x^9/9! -... Write a function, named sin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site