问题
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