plot approximation and absolute error of taylor series of e^x

8 ビュー (過去 30 日間)
Anon
Anon 2016 年 2 月 26 日
回答済み: Titus Edelhofer 2016 年 2 月 26 日
x = -10;
n = 0;
hold on
while n <= 50
f = (x.^n)./factorial(n);
plot (n,f,'g-o')
n = n + 1;
end
That is what I have so far.

回答 (1 件)

Titus Edelhofer
Titus Edelhofer 2016 年 2 月 26 日
Hi,
I guess the main error is to not sum: add f=1 in front of the loop and change
f = f + (x.^n) / factorial(n);
If you want to plot the error, you might do
subplot(2,1,1)
plot (n,f,'g-o')
hold on
subplot(2,1,2)
plot (n,f-exp(x),'g-o')
hold on
Last but not least: you might also think of computing f first (as a vector of length 50), and then plot ...
Titus

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by