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 CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by