Matlab Writing out Taylor Series for Cos X

3 ビュー (過去 30 日間)
NIGEL CHIN
NIGEL CHIN 2020 年 7 月 13 日
コメント済み: NIGEL CHIN 2020 年 7 月 15 日
How would I write out a taylor series without using the function? Currently i know how to write out everything but i am struggling in the last part where i have to display the values with the unknowns out in one line with the + symbol between them. This is what i got right now.
syms t y
for n = 0:5
d = diff(cos(t),n);
z = vpa(subs(d,t,0));
x = z*y^n/factorial(n);
disp(x)
end
Currently it will nly print out as follows below
1.0
0.0
-0.5*y^2
0.0
0.041666666666666666666666666666667*y^4
0.0
Is it possible for it to be printed out horizontally in a line?

採用された回答

Walter Roberson
Walter Roberson 2020 年 7 月 13 日
syms t y
for n = 0:5
d = diff(cos(t),n);
z = vpa(subs(d,t,0));
x(n+1) = z*y^n/factorial(n);
end
disp(x)
  3 件のコメント
Walter Roberson
Walter Roberson 2020 年 7 月 13 日
strjoin(arrayfun(@char, x, 'uniform', 0), ' + ')
To avoid having the 1/2 changed to 0.5, do not use vpa()
NIGEL CHIN
NIGEL CHIN 2020 年 7 月 15 日
Ah thanks so much. Ill give it a try

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by