Example 5.2.3 Nonlinear Surface at the Surface
| > | restart; |
| > | with(linalg):with(plots): |
| > | ge:=diff(u(x,t),t)=diff(u(x,t),x$2); |
| (1) |
| > | bc1:=u(x,t)-1; |
| (2) |
| > | bc2:=diff(u(x,t),x)-1+(u(x,t))^4; |
| (3) |
| > | IC:=u(x,0)=0; |
| (4) |
| > | N:=4; |
| (5) |
| > | L:=1; |
| (6) |
| > | dydxf:=1/2*(-u[2](t)-3*u[0](t)+4*u[1](t))/h; |
| (7) |
| > | dydxb:=1/2*(u[N-1](t)+3*u[N+1](t)-4*u[N](t))/h; |
| (8) |
| > | dydx:=1/2/h*(u[m+1](t)-u[m-1](t)); |
| (9) |
| > | d2ydx2:=1/h^2*(u[m-1](t)-2*u[m](t)+u[m+1](t)); |
| (10) |
| > | bc1:=subs(diff(u(x,t),x)=dydxf,u(x,t)=u[0](t),x=0,bc1); |
| (11) |
| > | bc2:=subs(diff(u(x,t),x)=dydxb,u(x,t)=u[N+1](t),x=1,bc2); |
| (12) |
| > | eq[0]:=diff(bc1,t); |
| (13) |
| > | eq[N+1]:=diff(bc2,t); |
| (14) |
| > | for i from 1 to N do eq[i]:=diff(u[i](t),t)= subs(diff(u(x,t),x$2) = subs(m=i,d2ydx2),diff(u(x,t),x) = subs(m=i,dydx),u(x,t)=u[i](t),x=i*h,rhs(ge));od; |
| (15) |
| > | h:=L/(N+1); |
| (16) |
| > | for i from 0 to N+1 do eq[i]:=eval(eq[i]);od; |
| (17) |
| > | eqs:=seq((eq[j]),j=0..N+1); |
| (18) |
| > | Y:=seq(u[i](t),i=0..N+1); |
| (19) |
| > | ICs:=u[0](0)=1,seq(u[i](0)=rhs(IC),i=1..N),u[N+1](0)=0; |
| (20) |
| > | sol:=dsolve({eqs,ICs},{Y},type=numeric,output=listprocedure); |
| (21) |
| > | for i from 0 to N+1 do U[i]:=subs(sol,u[i](t));od: |
| > | pp:=plot([seq(U[i](t),i=0..N+1)],t=0..1,thickness=4); |
| (22) |
| > | arw:=arrow(<0.1,1.03>,<0.2,-0.7>,width=[1/600,relative],head_width=[10,relative],head_length=[1/20,relative]):
pt:=textplot([[0.6,0.45,"Follow the arrow:"],seq([0.5,0.38-i*0.07,typeset(U[i],"(t)")],i=0..N+1)]): |
| > | display([pp,arw,pt],axes=boxed,title="Figure Exp. 5.2.5.",labels=[t,"u"]); |
![]() |
| > | tf:=.2; |
| (23) |
| > | M:=30; |
| (24) |
| > | T1:=[seq(tf*i/M,i=0..M)]; |
| (25) |
| > | PP:=matrix(N+2,M+1); |
| (26) |
| > | for i from 1 to N+2 do PP[i,1]:=evalf(subs(x=(i-1)*h,rhs(IC)));od: |
| > | for i from 1 to N+2 do for j from 2 to M+1 do PP[i,j]:=evalf(subs(t=T1[j],U[i-1](t)));od;od: |
| > | plotdata := [seq([ seq([(i-1)*h,T1[j],PP[i,j]], i=1..N+2)], j=1..M+1)]: |
| > | surfdata(plotdata,axes=boxed,title="Figure Exp. 5.2.6.",labels=[x,t,u],orientation=[-90,90]); |
![]() |
| > |