【问题标题】:Matlab Taylor series for e^x transforming to 1/e^x?用于 e^x 转换为 1/e^x 的 Matlab Taylor 系列?
【发布时间】: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


【解决方案1】:

要获得1/e^x,您只需计算e^(-x)。使用 -x 而不是 x 提供您的 eTaylor 函数,您就完成了!

 oneOverExp = eTaylor( -x, n ); 

PS,
最好是not to use i as a variable name in Matlab

【讨论】:

    猜你喜欢
    • 2022-06-10
    • 2016-01-16
    • 1970-01-01
    • 2013-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 1970-01-01
    相关资源
    最近更新 更多