【发布时间】:2014-11-25 00:25:38
【问题描述】:
我试图通过修改下面的代码来使其工作,以便 e^-x 可以工作,本质上我正在尝试修改它,以便 e^-x 是 1/e^x 我真的不知道该怎么做..这是我的代码..
function [result] = eTaylor(x, n)
% approximate e^x
% using first n non-zero terms of the Taylor series
% e^x = 1 + x + x^2/(2!) + x^3/(3!) + x^4/(4!) + ...
% Input arguments:
% x = real argument to function e^x
% n = number of non-zero terms of Taylor series
result = 0.0; term = 1.0;
for i = 1:1:n
result = result + term;
term = term*x/i;
end
【问题讨论】:
-
您使用泰勒展开式是因为您正在研究序列和系列,还是为了速度?
标签: matlab taylor-series