如何在Matlab脚本中将泰勒级数系数存储到数组中

lao*_*mao 4 matlab symbolic-math

这个问题是在.m脚本的上下文中.

我知道如何获得函数的泰勒级数,但我没有看到任何允许将系列的系数存储到数组中的命令 - sym2poly似乎不起作用.

如何将系数存储到数组中?例如,这个功能:

syms x
f = 1/(x^2+4*x+9)
Run Code Online (Sandbox Code Playgroud)

我们如何才能得到泰勒系数?fntlr不工作.

hor*_*ler 5

使用您的示例,符号taylorcoeffs函数可用于获取系数向量:

syms x
f = 1/(x^2 + 4*x + 9);
ts = taylor(f,x,0,'Order',4) % 4-th order Taylor series of f about 0
c = coeffs(ts)
Run Code Online (Sandbox Code Playgroud)

返回

ts =

(8*x^3)/6561 + (7*x^2)/729 - (4*x)/81 + 1/9


c =

[ 1/9, -4/81, 7/729, 8/6561]
Run Code Online (Sandbox Code Playgroud)

使用vpadouble转换c为十进制或浮点数.