Taylor expansion calculation of exp(x^2)
14次观看(最近30天)
Show older comments
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
0 Comments
Accepted Answer
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
More Answers (0)
See Also
美军陆军nity Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
开始狩猎!