2
$\begingroup$

If I have the output of Series, in terms of powers of my variable $x$, what is the quickest way to extract a part of the series, say for example the terms from $x^2$ to $x^5$, excluding those with lower and higher powers of $x$?

$\endgroup$
3
$\begingroup$
ser=Series[Exp[x], {x, 0, 10}]

$ 1+x+\frac{x^2}{2}+\frac{x^3}{6}+\frac{x^4}{24}+\frac{x^5}{120}+\frac{x^6}{720}+\frac{x^7}{5040}+\frac{x^8}{40320}+\frac{x^9}{362880}+\frac{x^{10}}{3628800}+O\left(x^{11}\right)$

Normal[ser][[3;;5]]

$ \frac{x^4}{24}+\frac{x^3}{6}+\frac{x^2}{2} $

Or

spartsF = FromDigits[Reverse[#[[3, #2 + 1 ;; #3 + 1]]], #[[1]]] #[[1]]^(#2) &;
spartsF[ser, 2, 4]

$x^2 \left(\frac{x^2}{24}+\frac{x}{6}+\frac{1}{2}\right)$

Or

spartF2 = With[{s = #, r = ##2}, Plus @@ (SeriesCoefficient[s, {x, 0, #}] x^# & /@ Range[r])] &;
spartF2[ser, 2, 4]

$\frac{x^4}{24}+\frac{x^3}{6}+\frac{x^2}{2}$

$\endgroup$
  • $\begingroup$ This looks very simple, thanks! But it doesn't help when there also are fractionary powers of $x$ in the series... Is there a way to make it work as SeriesCoefficient? $\endgroup$ – usumdelphini Mar 5 '15 at 22:15
  • $\begingroup$ @usumdelphini, please see the update. $\endgroup$ – kglr Mar 5 '15 at 22:44
  • $\begingroup$ The last two do not work for example for x^(-1/2) + 2 x^-1 + 3 x^(-3/2) + 4 x^-2 + 5 x^(1/2) + x^1 + x^(3/2) $\endgroup$ – usumdelphini Mar 5 '15 at 22:46
  • 1
    $\begingroup$ @usumdelphini, i think for series with fractional powers the second one is not salvageable; i will see if the last one can be fixed. $\endgroup$ – kglr Mar 5 '15 at 23:30
1
$\begingroup$
expr = Series[E^Sin[x], {x, 0, 10}] // Normal;

Cases[expr, a_.*x^n_?(2 <= # <= 5 &)] // Total

x^2/2 - x^4/8 - x^5/15

$\endgroup$
1
$\begingroup$
f=Normal[# + O[x]^(#2[[2]] + 1)] - Normal[# + O[x]^(#2[[1]])] &;

ser = Series[Exp[x], {x, 0, 10}];

f[ser, {2,5}]

(* x^2/2 + x^3/6 + x^4/24 + x^5/120 *)

This handles series where powers are not sequential/predictable, where the nice and compact use of Part in other answers fails/becomes difficult to use:

ser = Series[Exp[2 x^2]*x, {x, 0, 10}]
f[ser, {3, 6}]

(*

x+2 x^3+2 x^5+(4 x^7)/3+(2 x^9)/3+O[x]^11

2 x^3 + 2 x^5

*)
$\endgroup$
  • $\begingroup$ This fails to work for expansions around $\infty$ $\endgroup$ – usumdelphini Mar 6 '15 at 12:35
0
$\begingroup$
mySeries = Series[Exp[Sin[x]], {x, 0, 10}]

$1+x+\frac{x^2}{2}-\frac{x^4}{8}-\frac{x^5}{15}-\frac{x^6}{240}+\frac{x^7}{90}+\frac{31 x^8}{5760}+\frac{x^9}{5670}-\frac{2951 x^{10}}{3628800}+O\left(x^{11}\right)$

SeriesCoefficient[mySeries, #] & /@ Range[2, 5]

$\left\{\frac{1}{2},0,-\frac{1}{8},-\frac{1}{15}\right\}$

$\endgroup$
  • $\begingroup$ Thanks! And if I wanted the function, not only the coefficients? $\endgroup$ – usumdelphini Mar 5 '15 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.