find numerical solution of time-based partial differential equations
pdsolve(PDEsys, conditions, numeric, vars, options)
single or set or list of time-dependent partial differential equations in two independent variables
set or list of initial and boundary conditions
keyword indicating a numerical solution is to be obtained
(optional) dependent variable or a set or list of dependent variables for PDEsys
(optional) equations of the form keyword = value where keyword is one of 'indepvars', 'time', 'range', 'spacestep', 'timestep', 'bcopts', 'optimize', 'errorest', 'errortype', 'abstol', 'mintimestep' or 'maxtimestep'; specify options for the problem and its solution
The pdsolve(PDEsys,conditions,numeric,vars,options) command returns a module that can be used to compute numerical solutions for time-based PDE systems over a fixed finite 1-space interval.
The pdsolve/numeric routine uses finite difference methods to obtain these numerical solutions.
The PDE system PDEsys must be specified in diff notation.
Derivatives in the initial/boundary conditions conditions must be specified in indexed D notation (for example, for u(x,y), D1⁡u⁡0,y describes the normal derivative on the line x=0).
The vars parameter specifies the dependent variable(s) of the problem. For the solvers that can compute solutions of systems of PDEs, it provides an order for the dependent variables in the output.
For information on specifying the independent variables of the problem, see the Options section of this help page.
The solver has two modes of operation.
- The first mode of operation uses the default method, which is a centered implicit scheme, and is capable of finding solutions for higher order PDE or PDE systems. The PDE systems must be sufficiently close to a standard form for the method to find the numerical solution.
- The second mode of operation is strictly educational, and allows specification of a particular method to solve a PDE. This mode is restricted to a single PDE.
Note: This page describes only the default method. For information on the specified method approach, see Finding a Numerical Solution of a PDE Using a Specified Method. Both modes accept Dirichlet, Neumann, Robin, or periodic boundary conditions.
The optional equations for the default method are as follows.
Specifies the independent variables of the problem, and provides an order to the independent variables for returned procedures that compute the solution given the values of the independent variables.
The time argument specifies the name of the time variable for the problem, while the range argument specifies the spatial domain of the problem. Note: The values of both options are determined automatically if the boundary conditions are specified for both end points of the domain. These options are typically needed only for first order non-periodic problems where only one of the end points appears in the condition.
Specifies the spacing of the spatial points on the discrete mesh on which the solution is computed, and defaults to 1/20th of the spatial range of the problem, r−l, where l is the left boundary, and r is the right. Note: The spacing must be small enough that a sufficient number of points are in the spatial domain for the given method, boundary conditions, and spatial interpolation (see below). If the given value of spacestep does not fit into the input domain an integral number of times, the closest smaller step size that does is used. For problems using error estimates, or an adaptive approach, the total number of spatial points must be odd, so again, if this is not the case for the specified spacestep, then it is reduced to satisfy this requirement.
Provides the size of the time step used when integrating the PDE in the time direction, and defaults to the value of the spatial step spacestep before adjustments are made for fitting the interval.
Specifies the number of points used in discretization of the boundary conditions of the problem. It defaults to one greater than the differential order of the PDE in the space variable. This provides a first order accurate approximation to the boundary condition. Additional information is available below in Details.
Specifies the level of optimization to use in generating the method. Three types of optimization are available, true, partial, and false. The default partial optimization gives fairly good performance for a low time penalty in generating the method. A setting of false disables optimization altogether (not recommended). A setting of true causes pdsolve to call codegen[optimize] when constructing the numerical method. Because the additional time efficiency from the use of the fully optimized method is often offset by the time taken to perform the optimization, partial is the default setting.
These are all options related to error estimation, and error control, and are discussed in the pdsolve,numeric,errorcontrol page.
This option specifies that the underlying procedures used to evaluate the PDE should be compiled. By default this is false, as not all PDE can be compiled, and this option can only be used for the default PDE solution method. Problems typically run significantly faster when compiled. Note that in the event the compile fails, the problem will be silently run with compile=false.
The default method uses a second order (in space and time) centered, implicit finite difference scheme to obtain the computed solution. The number of points in the stencil of the finite difference scheme is one greater than the order of each equation.
Note: A first order accurate accurate boundary condition (the default) can be used for second order accurate method, and still provide a solution of second order accuracy. Use of boundary conditions with an order of accuracy that is too low degrades the accuracy of the solution, while use of boundary conditions with an order of accuracy that is too high may negatively impact the stability of the problem. For first and second order accurate methods, it is generally recommended to use one or two more boundary points than the differential order of the PDE in the space variable. For third and fourth order accurate methods it is generally recommended to use two or three more boundary points than the differential order of the PDE in the space variable.
PDE that are greater than first order in time are solved by converting to an equivalent first order system. Note: The conversion to first order is the expected one, namely that for any dependent variables that are higher than first order, variables representing all lower order time derivatives, and corresponding equations, are appended to the system. This choice of additional variables may not always be desirable, particularly when error control is in use, so often better performance can be obtained by choosing the first order system yourself. For more information on this topic, see pdsolve/numeric/firstorder.
Requested values that do not lie on a mesh point are computed using a Lagrange interpolation that uses 4 space points and 3 time points. The time points are chosen (whenever possible) so that only one time value is larger than the requested time.
The module returned by pdsolve/numeric has a number of methods that can be used to compute or view the solution of the input PDE: plot, plot3d, animate, and value. In addition, the settings method is available to query/set certain parameters of the solution process.
If the method returned by pdsolve/numeric is assigned to a name, say pde_module, the calling sequences that use the methods have the form pde_module:-method(arguments), where method is one of plot, plot3d, animate, value, and settings.
All methods involving the computation of solution values allow specification of multiple functions of the dependent and independent variables along with options specific to each function. This allows multiple plots to be displayed with the same command using different options for each. The full description of this argument is here. In the methods below, it is only referenced by name.
The default value of depspec is the first dependent variable of the problem with no additional options.
In the single function case, depspec can be a function of the dependent and independent variables, or a list consisting of a function of the dependent and independent variables followed by options. For example, u⁡x,t−sin⁡x, or u⁡x,t,color=blue.
If specifying multiple functions, depspec can be given as a list of functions or function/option combinations as described in the single function case. For example, u⁡x,t,w⁡x,t, or u⁡x,t+t,color=blue,w⁡x,t.
The plot method supports the following calling sequences.
plot(depspec, v1=numeric, options)
plot(v1=numeric, v2=range, options)
plot(depspec, v1=numeric, v2=range, options)
In the above calling sequences, the values/ranges specified by v1=numeric and v2=range, where v1,v2 are the names of the independent variables of the problem, specify the domain of the plot.
If only the value of v1 is specified (as is the case in the first two calling sequences), the functions are plotted with the value of that independent variable fixed as specified, and the domain of the plot ranging between the boundaries for the other independent variable. For example, specification of t=1 for a problem in u⁡x,t defined for x in the range 0,1 plots u⁡x,1 for x=0..1.
Note: If the spatial value is fixed, a time range must also be specified as in the third and fourth calling sequences.
If both a value and range are specified, v1 is fixed at the specified value and the plot is displayed over the range described by v2. The range for v2 must be contained in the boundaries for v2 (that is, the domain of the problem).
The options input specifies plot options to apply to all displayed plots that do not have a conflicting plot-specific option in the depspec.
Unlike plot, the plot method defaults to using the discrete points used on the computational domain, as controlled by timestep and/or spacestep. This can be changed by using the numpoints=npt plot option, in which case npt equally spaced points are computed by interpolation to obtain the plot.
The animate method supports the following calling sequences.
animate(v1=numeric, range, list, options)
animate(depspec, v1=numeric, range, list, options)
animate(v1=numeric, range, list, v2=range, options)
animate(depspec, v1=numeric, range, list, v2=range, options)
In the above calling sequences, the values/ranges specified for v1 give the animation, and the range specified by v2=range specifies the domain of each frame of the animation where v1,v2 are the names of the independent variables of the problem.
The specification of the values for v1 determines which values of v1 correspond to each frame of the animation. If specified as a range, the default of 16 frames is used to generate the animation, which can be changed using the option frames=integer. If specified as a list, the v1 values in the list are sorted, and correspond to the v1 values for each frame of the animation. Note: The v1=numeric specification, where v1 is the time variable, corresponds to the specification t=t0..numeric for t0<numeric and t=numeric..t0 for numeric<t0, where t0 is the initial time for the problem.
The v2=range argument (if provided) gives the range of the plot. If not present, this defaults to the interval between the boundaries of the problem.
Note: If v1 corresponds to the spatial variable, then v2=range must be provided.
The options input specifies plot options to apply to all displayed animations that do not have a conflicting plot-specific option in the depspec.
In addition, the title option has an additional feature. Using a floating point printf format code, you can display the time or space value for the current frame of the animation. For example, in a time-based animation, specifying title="t=%f" displays the specified title with the current time in place of %f in the animation. For more information, see the section on floating point formats on the printf help page.
Unlike plots[animate], the animate method defaults to using the discrete points used on the computational domain, as controlled by timestep or spacestep. This can be changed by using the numpoints=npt plot option, in which case npt equally spaced points are computed by interpolation to obtain the plot for each frame.
The plot3d method supports the following calling sequences.
plot3d(v1=numeric, range, options)
plot3d(depspec, v1=numeric, range, options)
plot3d(v1=numeric, range, v2=range, options)
plot3d(depspec, v1=numeric, range, v2=range, options)
In the above calling sequences, the values/ranges specified for v1 and v2 specify the rectangular area over which the 3-d plot is produced where v1,v2 are the names of the independent variables of the problem.
The specifications of v1,v2 define the domain for the plot. Like animate, the specification v1=numeric defines the interval from the initial point of the problem for the time variable.
The options input specifies plot3d options to apply to all displayed plots that do not have a conflicting plot-specific option in the depspec.
Unlike plot3d, the plot3d method supports explicit functions of the dependent and independent variables in the color specification for both the RGB and HUE types. For example, for a PDE problem in u⁡x,t, the RGB values can be specified by color=u⁡x,t,x−u⁡x,t2,x⁢tu⁡x,t.
The value method provides a mechanism to obtain the numerical values for the solution of the PDE or PDE system directly. The value method supports the following calling sequences.
value(depspec, v1=numeric, options)
value(v1=numeric, v2=range, options)
value(depspec, v1=numeric, v2=range, options)
In all cases, the value method returns a procedure or procedures that can be used to evaluate the solution at a point.
There are two distinct forms of output, bivariate functions (that is, the solution over the domain), or univariate functions (that is, solution profiles with one independent variable value fixed).
The first two calling sequences provide bivariate function output, so the returned function or functions are procedures that, given the values of both independent variables, return solution value(s). For these calling sequences, the solution is computed as each point is requested.
The remaining four calling sequences provide solution profiles with v1 fixed to the specified numeric function value. For these calling sequences, the solution is computed prior to output, and the returned procedure essentially provides an interpolation of that output. For the 5th and 6th calling sequences, v1 corresponds to the spatial variable. In this case, the returned procedures can only compute values for the time range specified by v2=range.
The only allowable option is used to specify the output type for the returned procedure(s), and like dsolve[numeric], it can be either output=procedurelist (the default) or output=listprocedure. The procedurelist output returns a single procedure that, if called with valid independent variable values, returns a list of equations for the independent variable values, and the dependent variable values as specified by the depspec if provided. The listprocedure output returns a list of equations, where the right-hand sides of these equations correspond to procedures that can be called to compute the numerical value indicated by the left-hand sides of the equations.
The settings command allows querying or setting of parameters for the computation of the solution. It supports the following calling sequences.
The first calling sequence is query-only, and reports settings that can be changed for the computation.
The second calling sequence changes settings based on the specified options. Valid options include timestep, and spacestep, which can be set in the same way as for the original call to pdsolve/numeric, with the exception that changing the spacestep value after creation of the solution module does not change the timestep. Adaptive modules have additional options for the settings method, see pdsolve,numeric,errorcontrol.
Simple wave equation:
PDE ≔ ∂∂t⁢u⁡x,t=−∂∂x⁢u⁡x,t
IBC ≔ u⁡x,0=sin⁡2⁢Pi⁢x,u⁡0,t=−sin⁡2⁢Pi⁢t
pds ≔ pdsolve⁡PDE,IBC,numeric,time=t,range=0..1
pds ≔ moduleexportplot,plot3d,animate,value,settings;...end module
p1 ≔ pds:-plot⁡t=0,numpoints=50:p2 ≔ pds:-plot⁡t=18,numpoints=50,color=blue:p3 ≔ pds:-plot⁡t=14,numpoints=50,color=green:plotsdisplay⁡p1,p2,p3
Plot of errors (exact solution is known):
esol ≔ sin⁡2⁢Pi⁢x−t
p2 ≔ pds:-plot⁡u−esol,t=18,numpoints=50,color=blue:p3 ≔ pds:-plot⁡u−esol,t=38,numpoints=50,color=green:plotsdisplay⁡p2,p3
Heat equation with left end fixed at constant temperature and right end insulated:
PDE ≔ ∂∂t⁢u⁡x,t=1⁢∂2∂x2⁢u⁡x,t10
IBC ≔ u⁡x,0=1,u⁡0,t=0,D1⁡u⁡1,t=0
pds ≔ pdsolve⁡PDE,IBC,numeric
p1 ≔ pds:-plot⁡t=0:p2 ≔ pds:-plot⁡t=110:p3 ≔ pds:-plot⁡t=12:p4 ≔ pds:-plot⁡t=1:p5 ≔ pds:-plot⁡t=2:plotsdisplay⁡p1,p2,p3,p4,p5,title=`Heat profile at t=0,0.1,0.5,1,2`
x=procx...end proc,t=1.,u⁡x,t=procx...end proc
uval ≔ rhs⁡op⁡3,
uval ≔ procx...end proc
Biharmonic: Bar with fixed ends and fixed angles:
PDE ≔ ∂2∂t2⁢u⁡x,t=−1⁢∂4∂x4⁢u⁡x,t10
IBC ≔ u⁡x,0=sin⁡Pi⁢x2,D2⁡u⁡x,0=0,u⁡−1,t=0,D1⁡u⁡−1,t=0,u⁡1,t=0,D1⁡u⁡1,t=0
pds ≔ pdsolve⁡PDE,IBC,numeric,spacestep=140
Animated (displaying the time in the title) with the following command:
pds:-animate⁡t=2,frames=50,title=time = %f
Solution just prior to formation of a shock for a nonlinear PDE:
PDE ≔ ∂∂t⁢u⁡x,t=−∂∂x⁢u⁡x,t⁢u⁡x,t
IBC ≔ u⁡x,0=ⅇ−16⁢x−1222,u⁡0,t=ⅇ−42
pds ≔ pdsolve⁡PDE,IBC,numeric,time=t,range=0..2,spacestep=1256,timestep=160
Animated with the following command:
An example of a system (also biharmonic)
PDE ≔ ∂∂t⁢u⁡x,t=−1⁢∂2∂x2⁢v⁡x,t20,∂∂t⁢v⁡x,t=∂2∂x2⁢u⁡x,t:
IBC ≔ u⁡x,0=sin⁡Pi⁢x,u⁡0,t=0,u⁡1,t=0,v⁡x,0=1−x,v⁡0,t=1,v⁡1,t=0:
pds ≔ pdsolve⁡PDE,IBC,numeric,spacestep=150
And plots of the solution v at t=0,0.1,...,0.5 can be obtained via
Boyce, W.E. and DiPrima, R.C. Elementary Differential Equations and Boundary Value Problems. New York: John Wiley & Sons, 1997.
Carrier, G.F. and Pearson, C.E. Partial Differential Equations: Theory and Technique. 2nd ed. Academic Press, 1988.
Strikwerda, J. C. Finite Difference Schemes and Partial Differential Equations. Wadsworth and Brooks/Cole, 1989.
Download Help Document
What kind of issue would you like to report? (Optional)