{VERSION 5 0 "IBM INTEL NT" "5.0" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Times" 1 12 255 0 0 1 0 1 0 0 1 0 0 0 0 1 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 1 }{CSTYLE "2D Comment" 2 18 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 } {CSTYLE "" 0 21 "" 0 1 0 0 0 1 0 0 0 0 2 0 0 0 0 1 }{CSTYLE "MYTEXT" -1 256 "Times" 1 14 0 0 0 0 0 1 0 0 0 0 0 0 0 1 }{PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Heading 1" -1 3 1 {CSTYLE "" -1 -1 "Ti mes" 1 18 0 128 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 6 6 1 0 1 0 2 2 0 1 } {PSTYLE "R3 Font 0" -1 256 1 {CSTYLE "" -1 -1 "Courier" 1 12 255 0 0 1 2 1 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "R3 Font 2 " -1 257 1 {CSTYLE "" -1 -1 "Courier" 1 12 0 0 255 1 2 2 2 2 2 2 1 1 1 1 }1 1 0 0 0 0 1 0 1 0 2 2 0 1 }{PSTYLE "Normal" -1 258 1 {CSTYLE " " -1 -1 "Times" 1 12 0 0 0 1 2 1 2 2 2 2 1 1 1 1 }3 1 0 0 0 0 1 0 1 0 2 2 0 1 }} {SECT 0 {SECT 0 {PARA 3 "" 0 "" {TEXT -1 37 "Diffusion equation---nume rical solver" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 62 "This program numer ically solves a diffusion equation on (0,1):" }}{PARA 258 "" 0 "" {XPPEDIT 18 0 "diff(u(x,t),t) = D*diff(u(x,t),`$`(x,2));" "6#/-%%diffG 6$-%\"uG6$%\"xG%\"tGF+*&%\"DG\"\"\"-F%6$-F(6$F*F+-%\"$G6$F*\"\"#F." } {TEXT -1 1 "+" }{XPPEDIT 18 0 "lambda*f(u(x,t));" "6#*&%'lambdaG\"\"\" -%\"fG6#-%\"uG6$%\"xG%\"tGF%" }}{PARA 0 "" 0 "" {TEXT -1 72 "with Neum ann boundary problem u_x(0,t)=u_x(L,t)=0 and initial condition " } {XPPEDIT 18 0 "u(x,0) = sin(Pi*x);" "6#/-%\"uG6$%\"xG\"\"!-%$sinG6#*&% #PiG\"\"\"F'F." }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 8 "restart;" }}}} {SECT 0 {PARA 3 "" 0 "" {TEXT -1 16 "Matrix Algorithm" }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "with(plots):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 91 "L is the length of spatial interval; k is the time step; \+ h is the grid size(spatial step); " }}{PARA 0 "" 0 "" {TEXT -1 65 "T i s the maximum time to be computed; d is the diffusion constant" }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 38 "L:=1; k:=0.004; h:=0.10; T:=2; d:=0 .1;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 108 "r and c are the constants appearing in the iteration formula (make sure that r<0.5 for stab le algorithm)" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 23 "r:= d*k/h^2; c:=1- 2*r; " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 10 "parameter " }{XPPEDIT 18 0 "lambda;" "6#%'lambdaG" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "lamb da:=12;" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 30 "Nonlinearity f(u,v) an d g(u,v)" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "f:=u->u*(1-u);" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 17 "Initial Condition" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 50 "u0:=y->evalf(0.01*sin(Pi*y)); plot(u0(y), y=0..L );" }{TEXT -1 1 " " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 26 "Generate th e spatial grids" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 44 "n:=floor(L/h)+1; x:=[seq(0+(i-1)*h,i=1..n)];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 24 "G enerate the time grids " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 44 "m:=floor (T/k)+1; t:=[seq(0+(j-1)*k,j=1..m)];" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 38 "Initialize the solution matrix by zero" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 48 "u:=matrix(n,m,[seq([seq(0.0,j=1..m)],i=1..n)]): " }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 23 "Input the initial value" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "for i from 1 to n do" }}{PARA 0 "> " 0 " " {MPLTEXT 1 0 23 " u[i,1]:=u0(x[i]); " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 4 "end:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 43 "Compute t he matrix by the iteration formula" }{MPLTEXT 1 0 0 "" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 24 "for j from 1 to m-1 do " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 49 " u[1,j+1]:=2*r*u[2,j]+c*u[1,j]+k*f(u[1,j]); " }} {PARA 0 "> " 0 "" {MPLTEXT 1 0 51 " u[n,j+1]:=2*r*u[n-1,j]+c*u[n, j]+k*f(u[n,j]); " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 25 " for i from 2 to n-1 do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 61 " u[i, j+1]:=r*u[ i-1,j]+c*u[i,j]+r*u[i+1,j]+k*f(u[i,j]); " }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 10 " end do;" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "end d o:" }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 9 "Animation" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 70 "Each of the following is a static plot of the s olution at a given time" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 " for j from 1 to m do" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 42 " U[j]:=plo t([seq([x[i],u[i,j]],i=1..n)]);" }}{PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "e nd do:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 58 "display the sequence of the static plots into an animation" }{MPLTEXT 1 0 0 "" }}{PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 45 "display([seq(U[j],j=1..m)], insequence=true); " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}{EXCHG {PARA 0 "" 0 "" {MPLTEXT 0 21 46 "**** THIS IS A PLOT THAT CAN BE ANIMATED ***** " }}}}}{MARK "3" 0 }{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 }{PAGENUMBERS 0 1 2 33 1 1 }