Example 3.2.15 Graetz Problem-Shooting Technique

> | restart:

> | with(plots):

> | eq:=diff(y(x),x$2)+1/x*diff(y(x),x)+lambda^2*(1-x^2)*y(x);

| (1)

> | eqlambda:=subs(y(x)=Y(x,lambda),eq);

| (2)

> | eqlambda:=diff(eqlambda,lambda);

| (3)

> | eqlambda:=subs(diff(Y(x,lambda),lambda)=y2(x),eqlambda);

| (4)

> | eqlambda:=subs(Y(x,lambda)=y(x),eqlambda);

| (5)

> | vars:=(y(x),y2(x));

| (6)

> | lambda0:=1;

| (7)

> | eqs:=subs(lambda=lambda0,eq),subs(lambda=lambda0,eqlambda);

| (8)

> | e:=1e-6;

| (9)

> | ICs:=(D(y)(0)=0,y(0)=1,y2(0)=0,D(y2)(0)=0);

| (10)

> | sol:=dsolve({eqs,ICs},{vars},type=numeric);

| (11)

> | sol(1);

| (12)

> | e:=1e-6;

| (13)

> | ICs:=(D(y)(e)=0,y(e)=1,y2(e)=0,D(y2)(e)=0);

| (14)

> | sol:=dsolve({eqs,ICs},{vars},type=numeric);

| (15)

> | sol(1);

| (16)

> | ypred:=rhs(sol(1)[2]);

| (17)

> | y2pred:=rhs(sol(1)[4]);

| (18)

> | lambda1:=lambda0+(0-ypred)/y2pred;

| (19)

> | err:=lambda1-lambda0;

| (20)

> | lambda0:=lambda1;

| (21)

> | k:=1;

| (22)

> | while err>1e-6 do

> | eqs:=subs(lambda=lambda0,eq),subs(lambda=lambda0,eqlambda);

> | sol:=dsolve({eqs,ICs},{vars},type=numeric);

> | ypred:=rhs(sol(1)[2]);

> | y2pred:=rhs(sol(1)[4]);

> | lambda1:=lambda0+(0-ypred)/y2pred;

> | err:=abs(lambda1-lambda0);

> | lambda0:=lambda1;k:=k+1;

> | end;

| (23)

> | lambda0;

| (24)

> | k;

| (25)

> | err;

| (26)

> | odeplot(sol,[x,y(x)],e..1,axes=boxed,thickness=3,title="Figure Exp. 3.2.31");

> | tol:=1e-10;rho:=1/3;

| (27)

> | lambdaguess:=[1,5,9,13,17];

| (28)

> | MM:=nops(lambdaguess);

| (29)

> | colorlist:=[black,red,blue,yellow,green];

| (30)

> | for i from 1 to MM do

> | lambda0:=lambdaguess[i];

> | k:=1;err:=1;

> | while err>tol do

> | eqs:=subs(lambda=lambda0,eq),subs(lambda=lambda0,eqlambda);

> | sol:=dsolve({eqs,ICs},{vars},type=numeric);

> | ypred:=rhs(sol(1)[2]);

> | y2pred:=rhs(sol(1)[4]);

> | lambda1:=lambda0+rho*(0-ypred)/y2pred;

> | err:=abs(lambda1-lambda0);

> | lambda0:=lambda1;k:=k+1;

> | end:

> | l[i]:=lambda0;

> | kk[i]:=k;

> | Err[i]:=err;

> | p[i]:=odeplot(sol,[x,y(x)],e..1,axes=boxed,thickness=3,color=colorlist[i]);

> | end:

> | seq(l[i],i=1..MM);

| (31)

> | seq(kk[i],i=1..MM);

| (32)

> | seq(Err[i],i=1..MM);

| (33)

> | arw:=arrow(<0.5,0.8>,<-0.45,-0.6>,width=[1/250, relative], head_length=[0.05, relative]): pt:=textplot([[0.8,0.95,"Follow the arrow"],seq([0.8,0.85-(i-1)*0.09,lambda=l[i]],i=1..MM)]);

| (34)

> | display({seq(p[i],i=1..MM),arw,pt},title="Figure Exp.3.2.32");

> |