Re: Taylor expansion

• To: mathgroup at yoda.physics.unc.edu
• Subject: Re: Taylor expansion
• From: withoff
• Date: Mon, 25 Oct 93 09:01:07 CDT

```> Hello mathgroup.
>
> I want the coefficients list of the 3rd order Taylor expansion of Cos[x]:
>
>    N[CoefficientList[ Normal[Series[ Cos[x],{x,0,3}]],x]]
>
> This gives me
>
>    {1., 0, -0.5}
>
> Note that the coefficient of the 3rd order term, being zero, is missing.
>
>    N[CoefficientList[ Normal[Series[ Cos[x],{x,0,4}]],x]]
>
> gives:
>
>    {1., 0, -0.5, 0, 0.0416667}
>
> What should I do against missing zeroes at the and of the List?
>
>
> Thank you!

========================================================================

I suspect that you can get what you want by introducing
a function to do it.

-----------------------------------------------------------------
Literal[SeriesCoefficientList[
SeriesData[var_, center_, coeffs_List, min_, max_, den_]]] :=
With[{len = Length[coeffs]},
Join[coeffs, Table[0, {max-min-len}] ] ]

In[45]:= SeriesCoefficientList[Series[ Cos[x],{x,0,3}]]

1
Out[45]= {1, 0, -(-), 0}
2
-----------------------------------------------------------------

The function Normal is designed to convert a series into
a sum, and since expr+0 evaluates to expr for any expression
expr, trailing zeros in the series will be discarded.

CoefficientList is designed to give a list of the coefficients
from a polynomial, and will not tack on extra zeros beyond
the degree of the polynomial.  CoefficientList[a + b x^2, x],
for example, does not return {a, 0, b, 0, 0, ...}.

Currently, CoefficientList[SeriesData[...], var] is equivalent to
CoefficientList[Normal[SeriesData[...]], var].

If you would like CoefficientList to behave like
SeriesCoefficientList when the first argument is a SeriesData
object and the variable (the second argument in CoefficientList)
is omitted or is the same as the expansion variable of of the
SeriesData object, you can do this by adding the appropriate rule.

-------------------------------------------------------------------
Begin["SpecialFunctions`Series`Private`"]

(* delete the current rule for Coefficient[SeriesData[...], var] *)

SeriesData /: CoefficientList[s_SeriesData, x___] =.

SeriesData/: Literal[CoefficientList[
SeriesData[var_, center_, coeffs_, min_, max_, den_], var_]] :=
With[{len = Length[coeffs]},
Join[coeffs, Table[0, {max-min-len}] ] ]

SeriesData/: CoefficientList[p_SeriesData] := CoefficientList[p, First[p]]

End[]
------------------------------------------------------------------

------------------------------------------------------------------
In[2]:= CoefficientList[Series[ Cos[x],{x,0,3}]]

1
Out[2]= {1, 0, -(-), 0}
2

In[3]:= CoefficientList[Series[ Cos[x],{x,0,3}], x]

1
Out[3]= {1, 0, -(-), 0}
2

In[4]:= CoefficientList[Series[ Cos[x],{x,0,4}]]

1      1
Out[4]= {1, 0, -(-), 0, --}
2      24
-----------------------------------------------------------------

Dave Withoff
Research and Development
Wolfram Research

```

• Prev by Date: Mathematica in Education
• Next by Date: NDSolve
• Previous by thread: Taylor expansion