The Shooting Method

>&ode2('diff(y,x,2)=y+'diff(y,x)*x,y,x); sol &= rhs(%)
2
x
-- 2
2 x x
sqrt(pi) %k1 E erf(-------) --
sqrt(2) 2
----------------------------- + %k2 E
sqrt(2)
>&solve([at(sol,x=0)=1,at(sol,x=1)=1],[%k1,%k2]); ...
> function y(x) &= sol with %[1]
2
x
-- - 1/2 2
2 x x
(sqrt(2) - sqrt(2) sqrt(E)) E erf(-------) --
sqrt(2) 2
-------------------------------------------------- + E
1
sqrt(2) erf(-------)
sqrt(2)
>&float(y(0)), &float(y(1)),
1.0
1.0
>&float(diffat(y(x),x=0))
- 0.45986222928643
>plot2d(&y(x),0,1); insimg;

>function f(x,u) := [u[2],u[1]+x*u[2]]
>u0=[1,mxmeval("diffat(y(x),x=0)")];
>x=0:0.01:1; u=adaptiverunge("f",x,u0); u[1,-1]
1
>function map shoot (dy0) := adaptiverunge("f",[0,1],[1,dy0])[1,2]
>shoot(mxmeval("diffat(y(x),x=0)"))
1
>plot2d("shoot",-2,2); insimg;

>bisect("shoot",-2,2,y=1)
-0.459862229287
>solve("shoot",0,y=1)
-0.459862229287
>
Examples Homepage