Taylor Series sine(x) infinite sum - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Taylor Series sine(x) infinite sum

shahrukh1shahrukh1 Posts: 1Member
I am writing a function that should be able to return to me the sine value of x using taylor series given x, and N which is how many terms

I have written my code
but I am not sure that it is correct. Can someone tell me if I wrote it correctly, and if not, how can I fix it.


[code]function output = sin_inf(x,n)

% result is the series approximation
result = x;

for i = 1:n
%the use of (-1)^i is to ensure that the method
%will add and subtract at the approriate interval
result = result + ( ( (-1).^i ) .* (x).^(2.*i + 1) )./factorial(2.*i + 1);
end



output = result;[/code]

Sign In or Register to comment.