how can I solve this problem

2 次查看(过去 30 天)
alhinai thuraiya
alhinai thuraiya 2016-10-10
回答: Guðmundur 2016-10-11
The cosine function can be evaluated by the following infinite series: cosx=1-(x^2)/2!+(x^4)/4!-(x^6)/6!+..... Write a MATLAB code to implement this formula in order to compute the value of cosx up to any n order term (i.e. x=pi/5,n=10)
  1 个评论
James Tursa
James Tursa 2016-10-10
What have you done so far? What specific problems are you having with your code?

请先登录,再进行评论。

回答(1 个)

Guðmundur
Guðmundur 2016-10-11
n = 10;
x = pi/5;
m = 0:2:2*n;
s = ones(1,n+1);
s(2:2:end) = -1;
cosx = sum((x.^m./factorial(m)).*s);

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by