Taylor Series of e^x on point 1

3 ビュー (過去 30 日間)
Panagiotis Panagopoulos Papageorgiou
Panagiotis Panagopoulos Papageorgiou 2019 年 6 月 27 日
回答済み: infinity 2019 年 6 月 27 日
Greetings,
I am trying to make my own script where I can approximate a function using a Taylor polynomial. However, when I try to use this method to the function e^x on point 1, I get this odd result:
(3060513257434037*x)/1125899906842624 + (3060513257434037*(x - 1)^2)/2251799813685248 + (3060513257434037*(x - 1)^3)/6755399441055744
Is there any way I can fix this? Thanks in advance!
Here's my code:
g = input('Please enter the function you want to approach as a Taylor series: ', 's');
p = input('Please enter the point around which the Taylor series will expand: ');
o = input('Please enter the order of the Taylor polynomial: ');
f = str2func(['@(x,y,z) ' g]);
F(1,1) = f(p);
for i = 1:o
syms x
f = matlabFunction(diff(f(x)));
F(i+1,1) = f(p);
end
syms x N
T = symsum((F(o,1)*(x-p)^N)/factorial(N), N, 0, o);
disp(T);
hold on
fplot(matlabFunction(T));
fplot(f);
hold off

回答 (1 件)

infinity
infinity 2019 年 6 月 27 日
Hello,
At least, I found a mistake in your program. Let see the line
T = symsum((F(o,1)*(x-p)^N)/factorial(N), N, 0, o);
The value of "F(o,1)" is not changed in the symsum since you told the function symsum that the variable is "N". To fix this, first you need to change "F(o,1)" to "F(N,1)".

カテゴリ

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