fprint:=proc(ncase,neqn,t,u) # # Function fprint displays the numerical and exact # solutions to the linear PDE # # Type variables local xl, xu, x, pi, ue, im: # # Declare global variables global nsteps: # # Problem parameters xl:=0.0: xu:=1.0: # # Print a heading for the solution at t = 0 if (t <= 0.0) then # # Label for ODE integrator # # Fixed step modified Euler if (ncase = 1) then printf(`\n\n euler2a integrator\n\n`); # # Variable step modified Euler elif (ncase = 2) then printf(`\n\n euler2b integrator\n\n`); # # Fixed step classical fourth order RK elif (ncase = 3) then printf(`\n\n rkc4a integrator\n\n`); # # Variable step classical fourth order RK elif (ncase = 4) then printf(`\n\n rkc4b integrator\n\n`); # # Fixed step RK Fehlberg 45 elif (ncase = 5) then printf(`\n\n rkc45a integrator\n\n`); # # Variable step RK Fehlberg 45 elif (ncase = 6) then printf(`\n\n rkc45b integrator\n\n`); end if: # # Heading printf(` ncase = %2d neqn = %2d nsteps = %3d \n\n`,ncase,neqn,nsteps); printf(` t u(num) u(exact) diff\n`); # # End of t = 0 heading end if: # # Numerical and analytical solution output # # Midpoint value of x x:=(xu-xl)/2.0: # # Analytical solution at midpoint pi:=evalf(Pi): ue:=exp(-pi*pi*t)*sin(pi*x): # # Grid index of midpoint im:=round((neqn+1)/2): # # Display the numerical and exact solutions, and their difference printf(`%5.2f %11.6f %11.6f %13.4e\n`,t,u[im],ue,u[im]-ue); # # End of fprint end: