pdsolve/numeric/method
find a numerical solution of a PDE using a specified method
Calling Sequence
Parameters
Description
Options
Examples
pdsolve(PDE, conditions, numeric, meth, options)
PDE
-
single partial differential equations in two independent variables
conditions
set or list initial and boundary conditions
numeric
keyword indicating a numerical solution is to be obtained
meth
name (symbol or indexed) of the form method=meth; select method to use for solution
options
(optional) equations of the form keyword = value
In addition to the default interface to pdsolve/numeric, which uses the default theta methods (the theta family of methods), additional functionality is available for use of numerical pdsolve for educational purposes.
This additional functionality includes the use of 11 standard methods, specification of numerical boundary conditions, specification of startup schemes for two-stage methods, and extensibility for your custom methods.
The use of pdsolve/numeric with these methods is restricted to a single parabolic/hyperbolic PDE that is first order in time.
As with the default method, pdsolve/numeric/method returns a module that can be used to plot solutions, or obtain procedures that provide their values. For information on the plot, animate, plot3d, value, and settings module members, see pdsolve/numeric.
The method argument specifies the method to use for the problem. The available methods are:
ForwardTime1Space[backward/forward]
CenteredTime1Space[backward/forward]
BackwardTime1Space[backward/forward]
Euler/ForwardTimeCenteredSpace
CrankNicholson/CenteredTimeCenteredSpace
BackwardEuler/BackwardTimeCenteredSpace
Box[backward/forward]
LaxFriedrichs
LaxWendroff
Leapfrog
DuFortFrankel
For a description of each method, including related problems, and instructions on creating a custom scheme, see pdsolve/numeric/methods.
The options available to pdsolve/numeric/method for these additional methods are as follows.
'time'
=
name
'range'
l..r
'spacestep'
'timestep'
'bcpts'
integer
'optimize'
boolean/symbol
'numericalbcs'
set, list or expression
'startup'
symbol
'startupsteps'
'startupnumbc'
The time=name, range=l..r, spacestep=numeric, timestep=numeric, bcpts=integer, and optimize=boolean/symbol options are the same as for the default method.
- The time and range options must be specified for problems that are first order in time and space with a boundary condition that involves only one end point (otherwise the time/space variables and range are detected automatically).
- The value of the spacestep option is the size of the spatial step to use for the discrete problem. It defaults to 1/20th the spatial range.
- The value of the timestep option is the size of the temporal step to use for the discrete problem. It defaults to the value of spacestep.
- The value of the bcpts option is the number of points used in the approximation of derivatives present in the boundary conditions.
- The optimize option controls the level of optimization used for generating the solution module. For more information, see pdsolve/numeric.
The numericalbcs=set, list or expression argument describes the numerical boundary conditions. It is required for the use of some methods with some PDEs.
For example, the Euler method relates the values of the solution for 3 consecutive points in the spatial domain. This means that boundary conditions must specify solution values at 2 points in the spatial domain. If the PDE is first order in space, only one natural boundary condition can be specified, and the scheme cannot be used directly.
Numerical boundary conditions allow specification of additional discrete equations, on the spatial mesh, which allow the method to be used for the PDE problem. These are often derived from an extrapolation, or a discretization of the PDE at or near the boundary that requires the additional condition.
The pdsolve command currently accepts two forms of numerical boundary conditions.
The first form specifies that the numerical boundary condition be obtained from one of the specified methods (likely more compact) applied to the input PDE near the boundary.
The second form allows significantly more control, but requires that numerical boundary condition be provided as a discrete equation that is a relationship amongst the discrete values of the dependent variable at the boundary. This form of numerical boundary condition can depend on the time and space variables of the problem, as well as the time and space step sizes (though the names used for the step sizes must be specified), and must be linear in the discrete dependent variable values.
The numericalbcs argument can be specified using the following forms:
`numericalbcs` =
[method, point]
expression
{expression, 'timestep'=symbol, 'spacestep'=symbol}
{[method[1], point[1]], ..., [method[n], point[n]],
expression[1], ..., expression[m],
'timestep'=symbol, 'spacestep'=symbol}
where method describes a method accepted by pdsolve (for example, Euler) or a custom method, point describes the boundary and offset to be used for the scheme generated by the method, timestep,spacestep specify the names used for the time and space step sizes in the numerical boundary condition, and the expression arguments are discrete forms of the numerical boundary conditions.
For the method specified numerical boundary conditions, the value of point indicates the leftmost or rightmost point to be used in the discrete formula obtained by the method. For example, if point is specified as 'n'-1 (where 'n' is some symbol) and the specified method has a width of 2, the condition is applied at the right boundary, and the solution values at the discrete points 'n'-1 and 'n'-2 are used in the discrete formula. As another example, if point is specified as 1 for the same method, the condition is applied at the left boundary, and the solution values at the discrete points 1, 2 are used in the discrete formula.
As a more detailed example, consider solution of the PDE ut+0.1⁢ux=0 using the LaxFriedrichs method. Since this problem is first order in space, only one natural boundary condition can be applied (one boundary condition on the left boundary). However, the method has a width of 3, so two conditions are needed, thus requiring the specification of a numerical boundary condition.
The additional argument numericalbcs=Box,n specifies the use of the Box method to obtain the required additional relation for the right boundary, and in fact is equivalent to the more complicated specification numericalbcs=spacestep=h,timestep=k,v1,n−v0,n+v1,n−1−v0,n−12⁢k+0.05000000000⁢v1,n−v1,n−1+v0,n−v0,n−1h=0 that corresponds to using expression specified numerical boundary conditions.
The expression specified numerical boundary conditions must be provided in a very particular form. The discrete dependent variable values must be given as indexed variables with the time index first, followed by the space index (that is, utimeidx,spaceidx). Values of the time index can range from −1 to 1, where a value of 1 indicates a value at the new time step (Note: The range is from 0 to 1 for single stage method). Values of the space index can range from 1 (left boundary) to n (right boundary) where n is any symbol that is consistent over the numerical boundary condition. If n is present in the space index, it must be of the form n−i where i=0,... (for example, u1,n2 and u1,2⁢n are not allowed).
For example, a numerical boundary condition that forces the value of the solution on the right boundary to be the same as the value of the solution at the first interior point can be specified as numericalbcs=u1,n−u1,n−1. A similar condition for the left boundary can be specified as numericalbcs=u1,1−u1,2.
The independent variable values also require some description. The spatial values must be given as the space variable indexed in the same manner as the spatial index described for the dependent variable values (for example, xn−1 or x1). The temporal values must be given relative to the 0 time index. For example, for the time for the dependent variable value u1,0, use the time value timevar+timestep instead of timevar.
As a summary example, consider the use of a backward time backward space discretization of the PDE ut+ux−sin⁡x⁢t as a numerical boundary condition for the right boundary. You can obtain the discretizations of the derivatives as ut=u1,n−u0,nk, and ux=u1,n−u1,n−1h. Because the expansion point of the discretization is at t+k,xn, replace the time and space variables in the discrete equation with these values. Hence, the specification of this numerical boundary condition is numericalbcs={u[1,n]−u[0,n]k+ux=u[1,n]−u[1,n−1]h−sint+k⁢xn,timestep=k,spacestep=h}
Note: This condition can be specified using the method form as numericalbcs=BackwardTime1Spacebackward,n.
Numerical boundary conditions must be provided if needed. Otherwise, Maple returns an error.
The startup=symbol, startupsteps=integer, and startupnumbc=set, list or expression arguments specify how to compute the additional stage required for two stage methods, such as Leapfrog and DuFortFrankel. Methods such as these require the solution values at the current and prior time step to compute the solution at a future time step. This is an issue in the first step of the time integration of the PDE, as only values at one time step are known (that is, the initial condition of the problem).
The startup argument can take two forms, a method specified form, or a function specified form. For the method specified form, the argument must be specified as startup=method, where method is any of the one stage methods available for use with numerical pdsolve. For the function specified form, the argument must be specified as startup=expression, where expression is any fully specified function of the time and space variables of the problem. If no startup argument is provided, the method form is used with the default Theta scheme.
The startupsteps argument (default value is 1) improves the accuracy of the computed solution if the startup method is of lower accuracy than the two stage method. It specifies one greater than the number of doubling steps used to compute the additional stage required by the main method, and is best described through an example.
Consider a PDE where the Leapfrog method is to be used as the primary method, and the Euler method is to be used as the startup method.
* If startupsteps=1, then for the current step size k, the Euler method is used to compute the solution value at t0+k, which is then used as the required additional stage.
* If startupsteps=2, then the Euler method is used to compute the solution value at t0+k2, and the Leapfrog method is used to compute the solution value at t0+k, which is then used as the required additional stage.
* If startupsteps=3, then the Euler method is used to compute the solution value at t0+k4, and the Leapfrog method is used to compute the solution value at t0+k2, then at t0+k.
* In general, for startupsteps=n, the Euler method is used to compute the solution value at t0+k2n−1, then the Leapfrog scheme is used to compute the solution value n−1 times at t0+k2n−2,t0+k2n−3,...,t0+k2,t0+k. The value at t0+k is used as the required additional stage.
This approach allows lower accuracy methods to be used as startup methods with little or no accuracy loss.
The startupnumbc argument specifies the numerical boundary conditions to use for the startup scheme. By default, pdsolve first attempts to obtain the startup solution using the startup method and the same numerical boundary conditions as the primary method. If this fails, pdsolve attempts to obtain the startup solution using the startup method with no numerical boundary conditions. This option is provided to cover cases where neither of these approaches are sufficient. For example, if the primary method requires two numerical boundary conditions, and the startup method requires only one, this approach fails, and startupnumbc must be used. Note that the specification of startupnumbc with the incorrect number of conditions, or use of the option if it is not needed, results in an error.
Basic one-way wave equation with boundary condition on the left using the ForwardTime1Space[backward] method.
PDE1≔diff⁡u⁡x,t,t=−12⁢diff⁡u⁡x,t,x
PDE1≔∂∂tu⁡x,t=−∂∂xu⁡x,t2
IBC1≔u⁡0,t=−sin⁡π⁢t2,u⁡x,0=sin⁡π⁢x
smod1≔pdsolve⁡PDE1,IBC1,numeric,time=t,range=0..1,method=ForwardTime1Spacebackward
smod1 ≔ moduleexportplot,plot3d,animate,value,settings;...end module
The exact solution to this problem is known. Obtain an error function at t=1.25
esol1≔sin⁡π⁢x−t2
errfunc≔smod1:-value⁡u⁡x,t−esol1,t=1.25,output=listprocedure
errfunc≔x=procx...end proc,t=1.25,u⁡x,t−sin⁡π⁢x−t2=procx...end proc
errfunc≔rhs⁡errfunc3
errfunc ≔ procx...end proc
Compute the maxnorm error over the interval.
maxerr≔max⁡seq⁡errfunc⁡i100,i=0..100
maxerr≔0.0299077658092643
Adjust half the step sizes and check that the error halves.
smod1:-settings⁡timestep=140,spacestep=140;errfunc2≔smod1:-value⁡u⁡x,t−esol1,t=1.25,output=listprocedure
errfunc2≔x=procx...end proc,t=1.25,u⁡x,t−sin⁡π⁢x−t2=procx...end proc
errfunc2≔rhs⁡errfunc23
errfunc2 ≔ procx...end proc
maxerr2≔max⁡seq⁡errfunc2⁡i100,i=0..100
maxerr2≔0.0156768632175617
maxerrmaxerr2
1.90776467168258
Use the CrankNicholson method on an inhomogeneous one-way wave equation. This requires a numerical boundary condition.
PDE2≔diff⁡u⁡x,t,t+110⁢exp⁡−t10⁢diff⁡u⁡x,t,x=cos⁡π⁢x−exp⁡−110⁢t⁢π⁢exp⁡−110⁢t5
PDE2≔∂∂tu⁡x,t+ⅇ−t10⁢∂∂xu⁡x,t10=cos⁡π⁢x−ⅇ−t10⁢π⁢ⅇ−t105
IBC2≔u⁡0,t=u⁡2,t,u⁡x,0=−sin⁡π⁢x
As a numerical boundary condition, choose a Box discretization of the PDE at the right boundary using the first interior point.
discs≔diff⁡u⁡x,t,t=u1,n−u0,n+u1,n−1−u0,n−12⁢k,diff⁡u⁡x,t,x=u1,n−u1,n−1+u0,n−u0,n−12⁢h
discs≔∂∂tu⁡x,t=u1,n−u0,n+u1,n−1−u0,n−12⁢k,∂∂xu⁡x,t=u1,n−u1,n−1+u0,n−u0,n−12⁢h
nbc≔spacestep=h,timestep=k,eval⁡PDE2,discs,t=t+k2,x=xn−h2
nbc≔spacestep=h,timestep=k,u1,n−u0,n+u1,n−1−u0,n−12⁢k+ⅇ−t10−k20⁢u1,n−u1,n−1+u0,n−u0,n−120⁢h=cos⁡π⁢xn−h2−ⅇ−t10−k20⁢π⁢ⅇ−t10−k205
Note: You do not need to specify time and range. They are implicitly defined using the periodic boundary condition.
smod2≔pdsolve⁡PDE2,IBC2,type=numeric,numericalbcs=nbc,method=CrankNicholson
smod2 ≔ moduleexportplot,plot3d,animate,value,settings;...end module
Again the exact solution of this problem is known. Examine the error.
esol2≔sin⁡π⁢x−exp⁡−110⁢t
esol2≔sin⁡π⁢x−ⅇ−t10
errfunc≔rhs⁡smod2:-value⁡u⁡x,t−esol2,t=1,output=listprocedure3
maxerr≔max⁡seq⁡errfunc⁡i50,i=0..100
maxerr≔0.00486456261189167
And with half the step size:
smod2:-settings⁡timestep=140,spacestep=140;errfunc2≔rhs⁡smod2:-value⁡u⁡x,t−esol2,t=1,output=listprocedure3
maxerr2≔max⁡seq⁡errfunc2⁡i50,i=0..100
maxerr2≔0.000305388741516921
15.9290830032846
The improvement is better than expected.
The Box scheme on the right boundary (without explicitly deriving the scheme) can be specified by using numericalbcs=[Box,n].
smod2b≔pdsolve⁡PDE2,IBC2,numeric,numericalbcs=Box,n,method=CrankNicholson
smod2b ≔ moduleexportplot,plot3d,animate,value,settings;...end module
errfunc≔rhs⁡smod2b:-value⁡u⁡x,t−esol2,t=1,output=listprocedure3
As an example of a two stage scheme, apply the DuFortFrankel method to a convection/diffusion equation with insulated boundary conditions.
PDE3≔diff⁡u⁡x,t,t=120⁢diff⁡u⁡x,t,x,x+12⁢diff⁡u⁡x,t,x
PDE3≔∂∂tu⁡x,t=∂2∂x2u⁡x,t20+∂∂xu⁡x,t2
IBC3≔u⁡x,0=cos⁡π⁢x2,D1⁡u⁡−12,t=0,D1⁡u⁡12,t=0
smod3≔pdsolve⁡PDE3,IBC3,type=numeric,method=DuFortFrankel,startup=Euler,timestep=150
smod3 ≔ moduleexportplot,plot3d,animate,value,settings;...end module
From this solution a series of plots at different times can be generated and displayed in the same plot.
p1≔smod3:-plot⁡t=0,color=red:p2≔smod3:-plot⁡t=16,color=maroon:p3≔smod3:-plot⁡t=13,color=blue:p4≔smod3:-plot⁡t=23,color=green:p5≔smod3:-plot⁡t=1,color=yellow:plotsdisplay⁡p1,p2,p3,p4,p5
See Also
diff
eval
pdsolve
pdsolve/numeric
pdsolve/numeric/methods
plot
plot3d
plots[animate]
plots[display]
seq
Download Help Document