Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I find a series solution to an ODE? I do not mean taking the Taylor series of an exact solution; I want to solve nasty nonlinear differential equations locally via plug and chug. Surely, that is a built-in option in Mathematica.

share|improve this question
Yes, there's a way. Do you have an example problem? – Mark McClure May 17 '13 at 3:45
Somewhat surprisingly, the procedure you want isn't built-in, but one could certainly write a routine for this task. – J. M. May 17 '13 at 3:46
@J.M. Not true! It's buried in the Holonomic context – Mark McClure May 17 '13 at 3:50
@Mark, I see. I had something like this in mind... still, if memory serves, the functions there can only do linear ODEs, not things like $y^\prime=1+y^2$. – J. M. May 17 '13 at 3:55
@Mark, after playing with some of those functions for a while, I'm not sure if using them is any better than forming a DifferentialRoot[] and then using Series[] for expansion (although I am sure those functions are used under the hood with what I'm proposing). – J. M. May 17 '13 at 5:06

This method of developing a truncated solution can be done as below. I illustrate with an example that DSolve does not seem much to like.

ode = x''[t] - t*x'[t] + Sin[t] == 0;
initconds = {x'[0] == 1, x[0] == 0};

We create a differentail operator to create this ode.

odeOperator = D[#, {t, 2}] - t*D[#, t] + Sin[t] &;

Now set up our Taylor series as a symbolic expansion using derivatives of x evaluated at the origin. I use an order of 15 but that is something one would probably make as an argument to a function, if automating all this.

xx = Series[x[t], {t, 0, 15}];

Next apply the differential operator and add the initial conditions. Then find a solution that makes all powers of `t vanish.

soln = SolveAlways[Join[{odeOperator[xx] == 0}, initconds], t];

Let's look at the Taylor polynomial.

truncatedSol = Normal[xx /. soln[[1]]]

(* Out[500]= t + t^5/120 + t^7/1260 + (29 t^9)/362880 + (
 13 t^11)/1995840 + (2861 t^13)/6227020800 + (4649 t^15)/163459296000 *)

To assess how accurate it might be I will compare with NDSolve.

approxSol = NDSolve[Join[{ode}, initconds], x[t], {t, 0, 4}];

Plot[{truncatedSol, x[t] /. approxSol[[1]]}, {t, 0, 4}]

enter image description here

share|improve this answer
+1 This is a good start. Power series solutions, though, are frequently used to obtain recursion equations for the coefficients (of any solution that might be analytic within a neighborhood of the point of expansion). It would be nice, then, to have a function that outputs these equations (given a differential operator as input), rather than just obtaining an approximate solution with a limited radius of accuracy. In order to analyze singular points, it would also be useful to consider slightly more general series of the form $z^\alpha(a_0+a_1z+a_2z^2+\cdots)$ for non-integral $\alpha$. – whuber May 17 '13 at 18:07
Thank you for your answer; it is very clear. My equation is very similar to the one you use; its nonlinear term is of the form sin(2f). I am more familiar with Maple which has the basic command dsolve(equation, series) and I was sure that MMA must have such a command also. – rick May 18 '13 at 2:02
@rick, that's a bit unclear; is the thing inside the sine the dependent or independent variable? – J. M. May 18 '13 at 15:03
My equation has the term sin (2y(x)) so it is far from linear. When looking at the documentation for NDSolve I did not see see where one might specify the integration method to use-I was searching for a Taylor series option. – rick May 19 '13 at 15:25

J.M. in a comment above alluded to this possibility. Using Series and DifferentialRoot seems like a great way to expand linear differential equations in series. It seems worth putting down in an answer due to its simplicity:

lde = {y''[x] - x*y'[x] + Sin[x] == 0, y'[0] == 1, y[0] == 0};
Series[DifferentialRoot[Function @@ {{y, x}, lde}][x], {x, 0, 15}]

(* x + x^5/120 + x^7/1260 + (29 x^9)/362880 + (13 x^11)/1995840 +
    (2861 x^13)/6227020800 + (4649 x^15)/163459296000 + O[x]^16 *)
share|improve this answer

Here's a way to develop a series solution for a quasilinear ODE with analytic coefficients, $y^{(n)}=f(x,y,y',\dots,y^{(n-1)})$. The main idea to fold Solve over the series expansion of the ODE solve for the derivatives of $y$, something like this:

  Flatten[{#1, Solve[#2 == 0 /. #1]}] &,
  ics,                                               (* initial conditions *)
  Series[ode /. Equal -> Subtract, {x, x0, n}][[3]]  (* series coefficients *)

Getting this idea to work for others without their having tweaking it takes some work. I've handled most of the things I've run into in the code below, but there are probably some things I have not tested. A malformed ODE may fail, probably ungracefully. Suggestions and comments are welcome if you run into other problems.

seriesDSolve[ode_, y_, iter : {x_, x0_, n_}, ics_: {}] := 
 Module[{dorder, coeff},
  dorder = Max[0, Cases[ode, Derivative[m_][y][x] :> m, Infinity]];
  (coeff = Fold[
         Solve[#2 == 0 /. #1, 
          Union@Cases[#2 /. #1, Derivative[m_][y][x0] /; m >= dorder, 
            Infinity]]}] &,
       SeriesCoefficient[ode /. Equal -> Subtract, {x, x0, k}],
       {k, 0, Max[n - dorder, 0]}]
    Series[y[x], iter] /. coeff) /; dorder > 0

Example (constructed from a comment by the OP):

 y''[x] + y'[x] == Sin[2 y[x]],
 y, {x, 0, 3},
 {y[0] -> a, y'[0] -> b}         (* symbolic initial values *)

Mathematica graphics

(Looking at it, I suppose it would be nice if the initial condition could be specified just like in DSolve. That would take some parsing and this approach evolved according to in-house needs -- that is to say, mine.)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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