The sine function can be evaluated via the following infinit
Solution
Ans:
function result = approx_sine(xrad, threshold)
%sin(x) = x – (x^3/3!) + (x^5/5!) – (x^7/7!) + · · ·
sinsum = xrad;
i = 3
terms = 1
realval = sin(xrad)
prevsign = 1
approx = (realval - sinsum)/realval
% if(approx < 0)
% approx = approx * -1
% end
while approx < threshold
prevsign = prevsign * -1
sinsum = sinsum + ( prevsign * (power(xrad, i) / factorial(i)))
i = i + 2
approx = (realval - sinsum)/realval
% if(approx < 0)
% approx = approx * -1
% end
end
terms = (i+1)/2
result = [sinsum terms]
end
x = pi/5;
threshold = 0.001;
[approx terms] = approx_sine(x, threshold)
threshold = 0.00001;
[approx terms] = approx_sine(x, threshold)
