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));
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));
> evalf(messy(.3));
Here is how Maple generates the infinite series solution.
> dsolve({diff(y(t),t)=y(t)^2+t,y(0)=1},y(t),series);
We can get more terms.
> Order:=20;
> dsolve({diff(y(t),t)=y(t)^2+t,y(0)=1},y(t),series);
> evalf(%);
> 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(.3);
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);
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(.3);
Standard numerical solution.
> stnumsol:=dsolve({diff(y(t),t)=y(t)^2+t,y(0)=1},numeric);
> stsol:= s ->subs(stnumsol(s),y(t));
> stsol(.3);
Finally we plot these different approximations and compare.
> plot([messy(t),series20(t)],t=-2..2,y=0..10,color=[red,blue]);
> plot([stsol,clsol],-2..2,y=0..10,color=[green,brown]);
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.