Comparison of approximation methods

We want to solve y' = y^2 + t. First we try our old friend dsolve.

> dsolve({diff(y(t),t)=y(t)^2+t,y(0)=1},y(t));

y(t) = ((3*GAMMA(2/3)^2*3^(2/3)-2*Pi*3^(5/6))/(3*GA...

Some day, when you are old enough, I'll tell you about the Airy functions. Suffice it to say this form of the solution may not be what you want. However you can use the evalf command to get real numbers out of it.

> messy:= t -> ((3*GAMMA(2/3)^2*3^(2/3)-2*Pi*3^(5/6))/(3*GAMMA(2/3)^2*3^(1/6)+2*Pi*3^(1/3)) *AiryAi(1,-t)+AiryBi(1,-t))/((3*GAMMA(2/3)^2*3^(2/3)-2*Pi*3^(5/6))/(3*GAMMA(2/3)^2*3^(1/6)+ 2*Pi*3^(1/3))*AiryAi(-t)+AiryBi(-t));

messy := proc (t) options operator, arrow; ((3*GAMM...

> evalf(messy(.3));

1.488022105

Here is how Maple generates the infinite series solution.

> dsolve({diff(y(t),t)=y(t)^2+t,y(0)=1},y(t),series);

y(t) = series(1+1*t+3/2*t^2+4/3*t^3+17/12*t^4+31/20...

We can get more terms.

> Order:=20;

Order := 20

> dsolve({diff(y(t),t)=y(t)^2+t,y(0)=1},y(t),series);

y(t) = series(1+1*t+3/2*t^2+4/3*t^3+17/12*t^4+31/20...
y(t) = series(1+1*t+3/2*t^2+4/3*t^3+17/12*t^4+31/20...
y(t) = series(1+1*t+3/2*t^2+4/3*t^3+17/12*t^4+31/20...

> evalf(%);

y(t) = series(1.+1.*t+1.500000000*t^2+1.333333333*t...
y(t) = series(1.+1.*t+1.500000000*t^2+1.333333333*t...
y(t) = series(1.+1.*t+1.500000000*t^2+1.333333333*t...
y(t) = series(1.+1.*t+1.500000000*t^2+1.333333333*t...

> series20:= t -> 1.+1.*t+1.500000000*t^2+1.333333333*t^3+1.416666667*t^4+1.550000000*t^5+1.655555556*t^6+ 1.776984127*t^7+1.911607143*t^8+2.053791887*t^9+2.206823192*t^10+2.371628788*t^11+2.548575771*t^12+ 2.738722484*t^13+2.943085412*t^14+3.162688223*t^15+3.398675488*t^16+3.652273375*t^17+ 3.924793402*t^18+4.217647738*t^19;

series20 := proc (t) options operator, arrow; 1.+1....
series20 := proc (t) options operator, arrow; 1.+1....
series20 := proc (t) options operator, arrow; 1.+1....
series20 := proc (t) options operator, arrow; 1.+1....

> series20(.3);

1.488022103

Next we do two different numerical solutions. The first uses Euler's method, but Maple calls it the classical method.

> clnumsol:=dsolve({diff(y(t),t)=y(t)^2+t,y(0)=1},numeric,method=classical);

clnumsol := proc (x_classical) local i, _s, st, en,...

The result is in the form a program, or procedure. We can convert this to a function.

> clsol:= s -> subs(clnumsol(s),y(t));

clsol := proc (s) options operator, arrow; subs(cln...

> clsol(.3);

1.48274494014505898

Standard numerical solution.

> stnumsol:=dsolve({diff(y(t),t)=y(t)^2+t,y(0)=1},numeric);

stnumsol := proc (rkf45_x) local i, comp_soln_data,...

> stsol:= s ->subs(stnumsol(s),y(t));

stsol := proc (s) options operator, arrow; subs(stn...

> stsol(.3);

1.48802210282841819

Finally we plot these different approximations and compare.

> plot([messy(t),series20(t)],t=-2..2,y=0..10,color=[red,blue]);

[Maple Plot]

> plot([stsol,clsol],-2..2,y=0..10,color=[green,brown]);

[Maple Plot]

Each method has its own pluses and minuses. We only touch on approximation methods in 305. See chapter 8 in your text or take math 360.