Taylor expansion calculation of exp(x^2)

14次观​​看(最近30天)
aroj bhattarai
aroj bhattarai 上30 Dec 2020
Dear Matlab users and experts,
I am aware that the exponential function is standarized as "exp" in Matlab . However, I need to calculate the function value exp(x^2) adjusting the (N) terms in the power series. Can anyone recommend the correct method to compute the function exp(x^2)?
My approach:
x = -3.0:0.1:3.0;
n = 12;
Taylor_p2 = 0;
forn = 0:N
Taylor_p2 = Taylor_p2 + (x.^(2.0.*n))./(factorial(n));% Taylor_p2 = exp(x^2)
end
isn't giving me the desired value. I am using R2020b Matlab version.
Many thanks in advance.
bhattarai

Accepted Answer

Ameer Hamza
Ameer Hamza 上30 Dec 2020
编辑:Ameer Hamza 上30 Dec 2020
The formula for taylor series is correct. Just increase the number of terms.
x = -3.0:0.1:3.0;
n = 12;
Taylor_p2 = 0;
forn = 0:N
Taylor_p2 = Taylor_p2 + (x.^(2.0.*n))./(factorial(n));% Taylor_p2 = exp(x^2)
end
p2 = exp(x.^2);
err = norm(p2-Taylor_p2);
plot(x, p2);
hold
plot(x, Taylor_p2,'*')
结果
>> err
err =
9.1544e-05
3 Comments
aroj bhattarai
aroj bhattarai 上1 Jan 2021
Dear John D'Errico,
您不应该期望有一个复杂的数字吗?该错误是在您的代码中,以及如何处理复杂结果。
是的,您是正确的,预期的复杂数量结果会导致ABS(X)> 1的收敛速度较慢。对于这种情况,是否有任何数学解决方案可以得到适当的结果?还是指数函数中的实际数量指数在根本上是不稳定和不稳定的?我为将原始问题引导到数学讨论而不是MATLAB问题的道歉。
bhattarai

Sign in to comment.

More Answers (0)

美军陆军nity Treasure Hunt

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

开始狩猎!