【问题标题】:Simplify symbolic expression in matlab and get only the coeeficents简化matlab中的符号表达式,只得到系数
【发布时间】:2021-02-12 22:33:41
【问题描述】:

我正在寻找在 Matlab 中找到泰勒级数的系数。我的做法是:

% Declare symbolic expression and function:
syms x;
f = exp(x);

% Calculate the taylor expansions in a concrete point:
T = taylor(f, x, 0.5);

% And finally I simplify the expression:
coefs = simplify(T)

但是返回的表达式是:

是的,它的表达是简化的,但实际上我想要的是:

其中每一项都乘以他的系数。我怎么能这样?诸如simplify(f, x, 0.5, 10 之类的选项,其中10 指的是简化步骤,在我的情况下不起作用。我也一直看到这个问题,问题是一样的:

How get to simplify a symbolic and numeric mixed expression in Matlab

【问题讨论】:

    标签: matlab coefficients taylor-series


    【解决方案1】:

    根据您想要的位数以及您想要的确切格式,这是一个示例:

    >> c = double(coeffs(T))
    c =
      Columns 1 through 4
       0.999966624859531   1.000395979357109   0.498051217190664   0.171741799031263
      Columns 5 through 6
       0.034348359806253   0.013739343922501
    >> digits 15
    >> x.^(0:numel(c)-1) * sym(c,'d').'
    ans =
    0.0137393439225011*x^5 + 0.0343483598062527*x^4 + 0.171741799031263*x^3 + 0.498051217190664*x^2 + 1.00039597935711*x + 0.999966624859531
    

    编辑

    请注意,您也可以使用 vpa( ) 而不是先转换为 double:

    >> c = coeffs(T)
    c =
    [ (2329*exp(1/2))/3840, (233*exp(1/2))/384, (29*exp(1/2))/96, (5*exp(1/2))/48, exp(1/2)/48, exp(1/2)/120]
    >> x.^(0:numel(c)-1) * vpa(c).'
    ans =
    0.0137393439225011*x^5 + 0.0343483598062527*x^4 + 0.171741799031263*x^3 + 0.498051217190664*x^2 + 1.00039597935711*x + 0.999966624859531
    

    【讨论】:

    • 谢谢@jamestursa 我也试过用 coeffs 但没有加倍......这一定是问题所在。
    猜你喜欢
    • 1970-01-01
    • 2016-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多