How do I make Taylor Series function for Sin(x)

I have given this question. i've tried to answer this with this code
x=2;
sini=1;
A=1;
fprintf('A= %2.0f sin(x) = %0.10f\n', A, sini)
fact=1
while(1)
A=A+1;
i=2*A-1;
fact = fact*A*(i-1);
sinj=sini+((-1)^(A+1))*((x)^i)/fact;
ea= abs((sinj-sini)/sinj);
fprintf('A= %2.0f sin(x) = %0.10f ea=%0.1e\n', A, sinj, ea)
if ea<=5e-11, break, end
sini=sinj;
end
I just based this with the sample Taylor series for cosine. I don't know this creates the right answer.
Please. I need some help. Thank you.

Answers (1)

I just based this with the sample Taylor series for cosine.
  • You need the sine, not the cosine.
  • 5*10^-11% is 5e-13.
  • The question asks for approximating sin(xi + h) by the Taylor series around sin(xi) and the offset h. Did you write down the formula on paper already? Then implementing it should be straight forward.
  • What kind of help do you need? What exactly is your question? Which detail of the code does not satisfy your needs?
I do not post a solution, because this is your homework.

1 Comment

now i realize why the output of my codes is not the same with my written solution. I forgot that 5*10^-11 is 5e-13. Thank you sir.

Sign in to comment.

Categories

Find more on Mathematics and Optimization in Help Center and File Exchange

Asked:

on 6 Jan 2018

Commented:

on 6 Jan 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!