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.
回答(1 个)
Jan
2018-1-6
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Mathematics and Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!