Function Repository Resource:

FrobeniusDSolve

Source Notebook

Compute an approximate Frobenius or power series solution to an ODE

Contributed by: Rauan Kaldybayev

ResourceFunction["FrobeniusDSolve"][eqn,u,x,x0,n]

solves a differential equation for the function u in the independent variable x using a Frobenius or power series.

ResourceFunction["FrobeniusDSolve"][x,x0,n,formula]

uses the algebraic formula supplied by the resource function FrobeniusDSolveFormula to quickly compute the solution.

Details

A Frobenius series has the form .
The output is of the form {soln1,soln2,,solnZ}, where Z is the order of the ODE and soln1,soln2,,solnZ are linearly independent solutions to the ODE. They are of the form , normalized by a0=1.
ResourceFunction["FrobeniusDSolve"] can solve linear homogeneous ODEs with polynomial coefficients.
Any linear ODE with polynomial coefficients can be written in the form for some (any) x0. Frobenius's method assumes solution of the form ; substituting this into the equation yields , where . To satisfy the equation, the coefficients before all power of x-x0 must be zero: for -Zk. From here, we can determine the possible values of the constant r for which a00, and then for each r, compute the coefficients. Read more at the related Wolfram Community post.
ResourceFunction["FrobeniusDSolve"] allows the option "ComputeError":
"ComputeError"Truecompute the error of the approximate solution
If "ComputeError" is True, the output is of the form {{soln1,err1},{soln2,err2},{solnZ,errZ}}, where Z is the order of the ODE, {solnk} are the linearly independent (approximate) solutions to the ODE, and {errk} are the errors of the appoximate solutions {solnk}. The error of an approximate solution to an ODE of the form Ly=0 is defined as . In other words, it is the absolute value of the remainder. The formulas for {errk} returned by ResourceFunction["FrobeniusDSolve"] are exact.
Approximate numbers make the function much faster while not affecting accuracy in a significant way. To solve a differential equation exactly using Frobenius's method, in general we would have to compute an infinite number of terms, which is of course impossible. Solutions obtained using Frobenius's method will thus always be approximate, even if exact numbers are used. Because the decrease in accuracy that comes from using approximate numbers is very small, using approximate numbers doesn't really affect the accuracy. And since doing computations with approximate numbers is much faster, they are used in ResourceFunction["FrobeniusDSolve"].

Examples

Basic Examples (2) 

Obtain an order six approximate solution to the ordinary differential equation 2x2y''+9x(x+1)y'-3y=0 using a Frobenius series around the singular point x0=0:

In[1]:=
{soln1, soln2} = ResourceFunction["FrobeniusDSolve"][
  2 x^2 y''[x] + 9 x (x + 1) y'[x] - 3 y[x] == 0, y, x, 0, 6]
Out[1]=

Plot the solutions:

In[2]:=
Plot[#, {x, 0, 2}, PlotStyle -> Blue, AxesLabel -> {"x", "y[x]"}, ImageSize -> Medium] & /@ {soln1, soln2}
Out[2]=

Compute a more accurate solution with n=40 and compare to the previous result:

In[3]:=
{soln1acc, soln2acc} = ResourceFunction["FrobeniusDSolve"][
   2 x^2 y''[x] + 9 x (x + 1) y'[x] - 3 y[x] == 0, y, x, 0, 40];
In[4]:=
Legended[
 Row[{Plot[{soln1acc, soln1}, {x, 0, 2}, ImageSize -> Medium, PlotStyle -> {{Green, Thick}, {Red, Dashed}}, AxesLabel -> {"x", "y[x]"}], "      ", Plot[{soln2acc, soln2}, {x, 0, 2}, ImageSize -> Medium, PlotStyle -> {{Green, Thick}, {Red, Dashed}}, AxesLabel -> {"x", "y[x]"}]}], LineLegend[{{Red, Dashed}, Green}, {"n = 6", "n = 40"}]]
Out[4]=

Plot the residuals Abs[x2y''+9x(x+1)y'-3y]:

In[5]:=
With[{err1 = Abs@Simplify@
     Expand[2 x^2 y''[x] + 9 x (x + 1) y'[x] - 3 y[x] /. (y -> Function[x, Null] /. Null -> soln1acc)],
  	err2 = Abs@Simplify@
     Expand[2 x^2 y''[x] + 9 x (x + 1) y'[x] - 3 y[x] /. (y -> Function[x, Null] /. Null -> soln2acc)]}, Labeled[Row[{Plot[err1, {x, 0, 2}, ImageSize -> Medium, PlotStyle ->  Blend[{Orange, Yellow}], PlotRange -> {0, 1.2  err1 /. x -> 2}, AxesLabel -> {"x", ""}], "      ", Plot[err2, {x, 0, 2}, ImageSize -> Medium, PlotStyle -> Blend[{Orange, Yellow}], PlotRange -> All, AxesLabel -> {"x", ""}]}], "Error, |\!\(\*FormBox[\(2\\\ \*SuperscriptBox[\(x\), \(2\)]\\\ y''\\\  + \\\ 9 \( x(x + 1)\)\\\ y'\\\  - \\\ 3  y\),
TraditionalForm]\)|", Top]
 ]
Out[5]=

As you can see, the solutions are very accurate. (see Author Notes for more information)


FrobeniusDSolve can also be used to solve equations that don't have singular points. Solve the pendulum equation θ''[t]=-θ[t] near the point t=-3, with n=16:

In[6]:=
pendulumsolns = ResourceFunction[
  "FrobeniusDSolve"][\[Theta]''[t] == -\[Theta][t], \[Theta], t, -3, 16]
Out[6]=

Plot the result:

In[7]:=
Plot[#, {t, -9, 3}, PlotStyle -> Blue, AxesLabel -> {"t", "\[Theta][t]"}] & /@ pendulumsolns
Out[7]=

Scope (3) 

The function can operate with complex numbers:

In[8]:=
ResourceFunction[
 "FrobeniusDSolve"][\[Psi]'[t] == I \[Psi][t], \[Psi], t, 0, 6]
Out[8]=

Find a degree 10 approximate solution for the fourth-order ODE (x-1)4f''''[x]=x(2+x)f[x]+x2(x-1)2f''[x]-19(x-1)3f'''[x] near the singular point x=1:

In[9]:=
order4solns = ResourceFunction[
  "FrobeniusDSolve"][(x - 1)^4 f''''[x] == x (2 + x) f[x] + x^2 (x - 1)^2 f''[x] - 19 (x - 1)^3 f'''[x], f, x, 1, 10]
Out[9]=

Plot the results:

In[10]:=
Plot[#, {x, 1, 3}, AxesLabel -> {"x", "f[x]"}] & /@ order4solns
Out[10]=

The inputs of the function can be symbolics:

In[11]:=
ResourceFunction["FrobeniusDSolve"][x'[t] + b x[t] == 0, x, t, 0, 3]
Out[11]=
In[12]:=
ResourceFunction["FrobeniusDSolve"][x'[t] + t x[t] == 0, x, t, T0, 3]
Out[12]=

Options (1) 

Set "ComputeError" to True to get a formula for the error, defined as the absolute value of the remainder, of a FrobeniusDSolve solution set (see Details and Options):

In[13]:=
{{frobsoln1, froberr1}, {frobsoln2, froberr2}} = ResourceFunction["FrobeniusDSolve"][f''[x] + (1 + x^2) f[x] == 0, f, x, 0, 10, "ComputeError" -> True]
Out[13]=

Properties and Relations (5) 

Use AsymptoticDSolveValue to solve the ODE ty''[t]+y[t]=0 near the singular point t=0:

In[14]:=
AsymptoticDSolveValue[t^2 y''[t] + (1.5 + t) y[t] == 0, y, {t, 0, 5}]
Out[14]=

Compare to the result from FrobeniusDSolve:

In[15]:=
ResourceFunction["FrobeniusDSolve"][
 t^2 y''[t] + (1.5 + t) y[t] == 0, y, t, 0, 5]
Out[15]=

Compare timings in milliseconds that FrobeniusDSolve and AsymptoticDSolveValue take to compute the 100th order power series approximation to y''+(1+x2)y=0:

In[16]:=
With[{eqn = (y''[x] + (1 + x^2) y[x] == 0), ncoefs = 100}, {
  		1000 First@
    RepeatedTiming[
     ResourceFunction["FrobeniusDSolve"][eqn, y, x, 0, ncoefs]],
  		1000 First@
    RepeatedTiming[AsymptoticDSolveValue[eqn, y, {x, 0, ncoefs}]]
  }]
Out[16]=

FrobeniusDSolve takes roughly 6 milliseconds to compute, while AsymptoticDSolveValue takes about 34. We can reduce computation time even further with the help of the resource function FrobeniusDSolveFormula:

In[17]:=
Block[{eqn = (y''[x] + (1 + x^2) y[x] == 0), ncoefs = 100, formula},
 	formula = FrobeniusDSolveFormula[eqn, y, x, 0];
 	1000 First@
   RepeatedTiming[
    ResourceFunction["FrobeniusDSolve"][x, 0, ncoefs, formula]]
 ]
Out[17]=

When the option "ComputeError" is set to True and FrobeniusDSolveFormula is used, the option "ComputeError" should be switched to True in FrobeniusDSolveFormula, too:

In[18]:=
With[{formula = FrobeniusDSolveFormula[f''[x] + (1 + x^2) f[x] == 0, f, x, 0, "ComputeError" -> True]}, ResourceFunction["FrobeniusDSolve"][x, 0, 10, formula, "ComputeError" -> True]]
Out[18]=

Possible Issues (3) 

Solutions obtained using Frobenius's method generally only have a finite convergence radius. Try to compute an approximate solution to the ODE (1+x3)y'=y with n=60:

In[19]:=
Plot[#, {x, 0, 2}, PlotRange -> {1, 3}] &@
 ResourceFunction["FrobeniusDSolve"][(1 + x^3) y'[x] == y[x], y, x, 0, 60]
Out[19]=

The plot looks good for x<1, however, for x>1 the solution starts diverging. To see that, notice that the ODE (1+x3)y'=y demands y' to be positive for x>0, y>0; the plot, however, suddenly goes down at x=1. Besides, the sharpness of the "cliff" looks very suspicious.


Frobenius's method only works near ordinary points or regular singular points. If solution near an irregular singular point is attempted, Frobenius's method would only yield some of the possible solutions or won't be able to find any solutions at all. Consider the ODE x3y''+xy'+(x2-1)y=0 near the singular point x=0:

In[20]:=
ResourceFunction["FrobeniusDSolve"][
 x^3 y''[x] + x y'[x] + (x^2 - 1) y[x] == 0, y, x, 0, 10]
Out[20]=

FrobeniusDSolve could only give one of the two linearly independent solutions. The other solution could not be found because it cannot be written in the form , as can be seen with the help of AsymptoticDSolveValue:

In[21]:=
AsymptoticDSolveValue[
 x^3 y''[x] + x y'[x] + (x^2 - 1) y[x] == 0, y, {x, 0, 10}]
Out[21]=

The parameter n must be at least Z+M, where Z is the order of the ODE and M is the highest power of x (the independent variable). If the ODE is y''''[t]=-(1+t2)y[t], then the order Z=4 and the highest power of t is M=2, so n must be at least 6:

In[22]:=
ResourceFunction["FrobeniusDSolve"][
 y''''[t] == -(1 + t^2) y[t], y, t, 0, 5]
Out[22]=

Neat Examples (2) 

Sometimes, the Frobenius series solution to an ODE consists of a finite number of terms. For example, below are a few examples when the exact solution only has one term in it:

In[23]:=
ResourceFunction["FrobeniusDSolve"][t y'[t] + y[t] == 0, y, t, 0, 10]
Out[23]=
In[24]:=
ResourceFunction["FrobeniusDSolve"][
 5 t^2 y''[t] + y[t] == 0, y, t, 0, 10]
Out[24]=

Sometimes, the solution terminates after a couple terms. While the second of the two solutions below goes on forever, the first one only has four nonzero terms:

In[25]:=
ResourceFunction["FrobeniusDSolve"][
 2 x^2 y''[x] + 7 x (x + 1) y'[x] - 3 y[x] == 0, y, x, 0, 10]
Out[25]=
In[26]:=
First[%]
Out[26]=

Publisher

Wolfram Summer Camp

Version History

  • 2.0.1 – 05 April 2021

Source Metadata

Related Resources

Author Notes

Plot the error of the approximate solutions to 2x2y''+9x(x+1)y'-3y=0 near the singular point x=0, with n=40 (obtained in Basic Examples):

In[1]:=
{soln1acc, soln2acc} = FrobeniusDSolve[2 x^2 y''[x] + 9 x (x + 1) y'[x] - 3 y[x] == 0, y, x, 0, 40];
With[{err1 = Abs@Simplify@
     Expand[2 x^2 y''[x] + 9 x (x + 1) y'[x] - 3 y[x] /. (y -> Function[x, Null] /. Null -> soln1acc)],
  	err2 = Abs@Simplify@
     Expand[2 x^2 y''[x] + 9 x (x + 1) y'[x] - 3 y[x] /. (y -> Function[x, Null] /. Null -> soln2acc)]},
 	Labeled[
  Row[{Plot[err1, {x, 0, 2}, ImageSize -> Medium, PlotStyle ->  Blend[{Orange, Yellow}], PlotRange -> {0, 1.2  err1 /. x -> 2}, AxesLabel -> {"x", ""}], "      ",
    			Plot[err2, {x, 0, 2}, ImageSize -> Medium, PlotStyle -> Blend[{Orange, Yellow}], PlotRange -> All, AxesLabel -> {"x", ""}]}],
  		"Error, |\!\(\*FormBox[\(2\\\ \*SuperscriptBox[\(x\), \(2\)]\\\ y''\\\  + \\\ 9 \( x(x + 1)\)\\\ y'\\\  - \\\ 3  y\),
TraditionalForm]\)|", Top
  	]
 ]

The error of the first solution (the one proportional to ) goes to infinity as x0 simply because there is some numerical error in the coefficients aj. When multiplied by, a tiniest error in aj leads to a huge residual, even though the true error is still very small. If, for example, the ODE to be solved is 0xy'+y=0, then ; a small error in C leads to a huge residual at x0 but is insignificant for larger x. We can confirm the hypothesis by looking at the asymptotic expansion of the residual near x=0:

In[2]:=
Asymptotic[
 Simplify@
  Expand[2 x^2 y''[x] + 9 x (x + 1) y'[x] - 3 y[x] /. (y -> Function[x, Null] /. Null -> soln1acc)], x -> 0]

The coefficients are of order 10-14, which is roughly the (default) numerical accuracy of the Wolfram Language.

License Information