问题描述
这个问题是在.m脚本的上下文中进行的.
This question is in the context of a .m script.
我知道如何获得一个函数的泰勒级数,但是我看不到任何命令可以使该系列的系数存储到数组中-sym2poly
似乎不起作用.
I know how to get the Taylor series of a function, but I do not see any command that allows one to store the series' coefficients into an array – sym2poly
does not seem to work.
如何将系数存储到数组中?例如,此功能:
How does one store coefficients into an array? For example, this function:
syms x
f = 1/(x^2+4*x+9)
我们将如何获得泰勒系数? fntlr
无效.
How would we be able to get the Taylor coefficients? fntlr
did not work.
推荐答案
使用您的示例,符号 taylor
和 coeffs
函数获得系数向量:
Using your example, the symbolic taylor
and coeffs
functions can be used to obtain a vector of coefficients:
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)
返回
ts =
(8*x^3)/6561 + (7*x^2)/729 - (4*x)/81 + 1/9
c =
[ 1/9, -4/81, 7/729, 8/6561]
使用 vpa
或 double
可以将c
转换为小数或浮点数.
Use vpa
or double
to convert c
to decimal or floating point.
这篇关于如何在Matlab脚本中将泰勒级数系数存储到数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!