在matlab中简化符号表达式,只得到系数

在matlab中简化符号表达式,只得到系数,matlab,coefficients,taylor-series,Matlab,Coefficients,Taylor Series,我想从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) 但返回的表达式是: 是的,表达

我想从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
指简化步骤之类的选项在我的情况下不起作用。我也看到了这个问题,问题是相同的:


根据需要的位数和结果的确切格式,下面是一个示例:

>> 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()而不是转换为双精度优先:

>> 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,我也尝试过使用coefs,但没有使用double…这一定是问题所在。