How to store Taylor series coefficients into an array in Matlab script

浪子不回头ぞ 提交于 2019-12-10 16:32:19

问题


This question is in the context of a .m script.

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)

How would we be able to get the Taylor coefficients? fntlr did not work.


回答1:


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)

which returns

ts =

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


c =

[ 1/9, -4/81, 7/729, 8/6561]

Use vpa or double to convert c to decimal or floating point.



来源:https://stackoverflow.com/questions/33713271/how-to-store-taylor-series-coefficients-into-an-array-in-matlab-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!