find numerical solution of ordinary differential equations - Maple Help

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : Mathematics : Factorization and Solving Equations : Numerical Solutions : dsolve/numeric

dsolve/numeric - find numerical solution of ordinary differential equations

Calling Sequence

dsolve(odesys, numeric, vars, options)

dsolve(numeric, procopts, options)




set or list; ordinary differential or differential-algebraic equation(s) and initial/boundary conditions



name; instruct dsolve to find a numerical solution



(optional) any indeterminate function of one variable, or a set or list of them, representing the unknowns of the ODE problem



(required if odesys is not present) options that specify a procedure defined system (procedure, initial, start, number, and procvars). For more information, see dsolve[numeric,IVP].



(optional) equations of the form keyword = value



The dsolve command with the numeric or type=numeric option finds a numerical solution for the ODE or ODE system. If the optional equation method=numericmethod is provided (where numericmethod is one of rkf45, ck45, rosenbrock, bvp, rkf45_dae, ck45_dae, rosenbrock_dae, dverk78, lsode, gear, taylorseries, mebdfi, or classical), dsolve uses that method to obtain the numerical solution.


Both initial and boundary value problems can be numerically solved, as well as initial differential algebraic problems. For a system input, the type of problem is automatically detected, but for some DAE problems it may be necessary to specify the method.


By default, a procedure is returned that can be used to obtain solution values if given the value of the independent variable.


The default for initial value problems (IVP) is a Runge-Kutta Fehlberg method that produces a fifth order accurate solution (For more information, see rkf45 or numeric,IVP). For boundary value problems (BVP), a finite difference technique with Richardson extrapolation is used (For more information, see numeric,BVP). For differential-algebraic IVP problems (DAE), a modification of the rkf45 method is used (For more information, see dae_extension).


All IVP methods can be used for complex-valued IVPs with a real-valued independent variable (though for the default stiff and nonstiff IVP methods, it may be necessary to specify that the problem is complex via the complex option). None of the BVP or DAE methods can currently be used for complex-valued problems, requiring the system be converted to a real system before calling dsolve.


The IVP and DAE methods have additional capabilities for the returned solution procedure. Specifically, it is possible to query the last computed solution value (useful for problems with singularities), query the initial data, and change the initial data for some solution procedures (DAE methods support a subset of this). For more information, see numeric,IVP and numeric,DAE.


When the set of dependent variables vars is specified as a list, then this specifies the order of the dependent variables as they appear in the output. The order is otherwise alphabetical in the dependent variable name.



The high-level options, most common to IVPs, BVPs, and DAEs are as follows.

'output'        =

keyword or array

'stiff'         =


'events'        =


'event_pre'     =


'event_maxiter' =


'range'         =


'abserr'        =

numeric or list

'relerr'        =


'known'         =

name or list of names

'optimize'      =



'output'= keyword or array


Keyword that can take the values procedurelist, listprocedure, operator, or piecewise, or an array or Array that gives the values of the independent variable at which solution values are desired.


The default keyword is procedurelist, which gives the output from dsolve as a procedure. This procedure accepts the value of the independent variable as an argument, and it returns a list of the solution values of the form variable=value, where the left-hand sides are the names of the independent variable, the dependent variable(s) and their derivatives (for higher order equations), and the right-hand sides are the corresponding computed solution values.


The listprocedure keyword gives the output as a list of equations of the form variable=procedure, where the left-hand sides are the names of the independent variable, the dependent variable(s) and derivatives, and the right-hand sides are procedures that can be used to compute the corresponding solution components. This output form is most useful when the returned procedure is to be used later with, for example, fsolve.


The operator keyword gives the output as a list of equations of the form operator=procedure, where the left-hand sides are operators that can be applied to an independent variable value to give the function or derivative evaluated at a point, and the right-hand sides are procedures that can be used to compute the corresponding solution components. This output form is most useful for shortcut evaluation forms where the returned list is to be evaluated at a point (for example, result1).


The piecewise keyword is available only for non-stiff and stiff default IVP and DAE methods (rkf45, ck45, rosenbrock, rkf45_dae, ck45_dae, and rosenbrock_dae) and the taylorseries method. It provides output as a list of equations of the form variable=pwfunc, where the left-hand sides are the names of the independent variable, the dependent variable(s) and derivatives, and the right-hand sides are piecewise polynomial functions describing the corresponding solution components. These piecewise functions are obtained from the method interpolants for each step of the computation. In addition, the form of the piecewise polynomials can be specified using an index on the piecewise output request. Specification of output=piecewise[horner] provides output in terms of horner-form polynomials (the default for taylorseries), while specification of output=piecewise[polynomial] provides output in terms of standard polynomial form (the default for all other methods). Use of this output form requires that the 'range' argument be used to specify to dsolve/numeric the desired range of the piecewise function.


If an array is used, it must be a vector of floats that defines the values of the independent variable at which solution values are desired. When this option is given, a 2 x 1 matrix is returned (instead of a solution procedure). The 1,1 entry is an array containing the name of the independent variable and the names of the dependent variable(s) and derivatives. The 2,1 entry is a matrix. The first column of this matrix is a copy of the output vector, that is, the values of the independent variable. The other columns are values of the dependent variable(s) and derivatives corresponding to the vector of names in 1,1. Row i of this matrix is the vector containing both the value of the independent variable and the values of the dependent variables evaluated at element i of the output array.


Note: If an Array is used, then the output is the same as for an array except the newer Array and Matrix datatypes are used in the output. For a large number of output points and/or solution components, the output data may not be directly visible because there is a default size at which the representation of an Array or Matrix is displayed instead of an inline display of the data itself. For more information, see interface(rtablesize).




'stiff'= boolean


Boolean that is used only for IVP and DAE. Setting stiff=true without selecting a method specifies that the default stiff methods (rosenbrock or rosenbrock_dae) must be used instead of the default non-stiff methods (rkf45 or rkf45_dae). When the method is also specified, a consistency check is performed to verify that the method matches with the 'stiff' value. For more information on the phenomena of stiffness, see dsolve[Stiffness].




'events'= list


'event_pre'= keyword


'event_maxiter'= integer


Arguments that are available only for real-valued IVPs or DAEs using the non-stiff and stiff methods, rkf45, ck45, rosenbrock, rkf45_dae, ck45_dae, or rosenbrock_dae, and are used to specify and control the behavior of events. These options are discussed in detail in dsolve[Events].




'range'= numeric...numeric


Values that specify the range of the independent variable over which solution values are desired.


For IVPs and DAEs this option is used only by the non-stiff and stiff methods (rkf45, ck45, rosenbrock, rkf45_dae, ck45_dae, rosenbrock_dae) and the taylorseries method. It has two purposes for procedure-type output. If 'range' is used, then the call to dsolve computes the solution over the desired range before returning, storing that solution for later calls to the returned procedure, which then compute the return values through interpolation.




- When computing a numerical solution for a problem that has large regions where the solution is changing slowly, and small regions where the solution is changing rapidly, use of 'range' combined with the refine option of odeplot (rkf45*, ck45*, and rosenbrock* only) allows better plotting of the details of the solution. If 'range' is not used, then the call to dsolve returns a procedure that does not store the computed solution, but rather computes the solution whenever a point is requested.


- For long-time integration problems it is suggested that 'range' not be used, as the storage of the entire solution can consume a fair bit of memory.


For the BVP method, this option is only needed when the BVP method is to be used to solve an IVP with a global error bound, as for BVP the information can be inferred from the boundary conditions in deqns. For more information, see numeric,BVP.




'abserr'= numeric or list


Numeric value that gives a limit on the absolute error tolerance for a successful step in the IVP and DAE cases, and a measure of the maximum error between the computed solution and the exact solution in the BVP case (in all but exceptional systems). It is supported by all methods except the classical methods (as all classical methods are implemented with a fixed step size and no error control). The list form of abserr is available for the rkf45*, ck45*, rosenbrock*, and mebdfi IVP and DAE methods, and allows specification of absolute error tolerances that are different for each dependent variable, or for each solution component. More detail on this can be found in the dsolve[numeric,IVP] page and the dsolve[Error_Control] page.




'relerr'= numeric


Numeric value that gives a limit on the relative error tolerance for a successful step for an IVP or DAE. This option works in conjunction with 'abserr'. It is supported by all methods except classical, taylorseries, and bvp.


Defaults for 'abserr' and 'relerr' are specific to each method, but it should be noted that the default error tolerance for the non-stiff methods rkf45 and ck45 is now fixed (rather than controlled by the value of Digits).


For a detailed discussion about error control, see dsolve[Error_Control].




'known'= name or list of names


Provides a list of functions that should be considered as known when examining the system. This allows for specification of a system containing user-defined functions. Each user defined function must always return numerical values when given numeric input, and must return unevaluated when given name input. For an illustration of the use of this option, see the Examples section below.


Note: In most cases, use of a system with a user-defined function prevents the use of evalhf within dsolve, so obtaining a solution using this facility will run noticeably slower than specification of the system in terms of known functions (when it is possible to express the system in this way).


All methods except taylorseries, rosenbrock, and rosenbrock_dae support this option directly, but for these two methods additional information is required. The key problem is that these two methods require information on the derivatives of the input ODE system, which is not directly available when functions are procedure defined. It is still possible to use these methods with 'known', as long as the derivatives of the function are defined via use of one or more `diff/` rules. The rosenbrock method requires only a single derivative, but the taylorseries method requires derivatives to arbitrary order, so with taylorseries it is useful only if some finite derivative of the 'known' functions can be represented as a function instead of a procedure, in which case, all derivatives up to that function derivative must have a diff rule defined. The rosenbrock_dae method may require more than a single derivative, as the DAE preprocessing may need to differentiate the input system.


For taylorseries, rosenbrock, and rosenbrock_dae use of multiple argument functions, or functions that also depend on the dependent variables or derivatives of the problem are tricky, and have some limitations. The details of this are deferred to the respective help pages.




'optimize'= boolean


Boolean that tells dsolve to optimize the input system for computation. This adds an up-front cost, with the possible reward that the core computation itself will be faster. This is false by default for IVP and BVP problems, and true by default for DAE problems (which typically derive the most benefit from optimization). Systems containing conditional evaluation functions (such as piecewise) should not use optimize=true, as this will sometimes result in a slower computation. This option is available only for system defined problems, and for all methods except taylorseries (which uses its own form of optimization).




All other options, including options for specification of procedures for the evaluation of the ODE system, and options specific to IVP or BVP are discussed in dsolve[numeric,IVP] and dsolve[numeric,BVP], or the help pages specific to each method.



When Digits<=evalhfDigits, numerical solutions are computed in double precision (hardware floats). This is the default, as on initialization Maple sets Digits to 10. Explicit setting of Digits>evalhfDigits causes dsolve to compute numerical solutions using Maple floats instead of hardware floats. The precision of a computation is fixed in the call to dsolve, so for procedure outputs, once the procedure is created, further changes to the setting of Digits should have no effect on the computed solution.


Numerical solutions can be used in combination with fsolve, but the Digits setting on the call to fsolve must be lower (usually by 5 or more) than the precision for the dsolve procedure (because fsolve requires a higher accuracy on the residual than the current Digits setting). The rkf45, ck45, rosenbrock, and taylorseries methods, when computing solution values with an interpolant, work around this problem by computing the interpolant with the current setting of Digits when called from fsolve. An example of the problem is presented in the last example below.


Results can be plotted by using the odeplot function in the plots package.


ODE systems can also be interactively solved and plotted with the dsolve[interactive] Maplet interface.


Solve a system of ODEs






If you specify the set of dependent variables as a list, those variables appear in the same order in the output.





Straightforward second order IVP:






dsol1:=procx_rkf45...end proc











Same second order IVP with operator output:


dsol1b:=t&equals;proct...end proc&comma;y&equals;proct...end proc&comma;Dy&equals;proct...end proc











First order IVP:


dsol2:=x&equals;procx...end proc&comma;yx&equals;procx...end proc



fy2:=procx...end proc





First order IVP with piecewise output:




Stiff nonlinear problem:







Linear BVP:


dsol4:=procx_bvp...end proc














Nonlinear BVP:












dsol6:=procx_rkf45_dae...end proc





Use with fsolve:








dsol7:=x&equals;procx...end proc&comma;yx&equals;procx...end proc



yproc:=procx...end proc


Attempt with same Digits setting, returns unevaluated.

fsolve(yproc(x)=1e5, x=4..7);



The same command with Digits set to 15 succeeds.




fsolve(yproc(x)=1e5, x=4..7);






Use of known option:

f := proc(x) local t;
   if not type(evalf(x),'numeric') then
   end if;
end proc;

f:=procxlocalt&semi;ifnottypeevalfx&comma;&apos;numeric&apos;then&apos;procname&apos;xelseevalfIntexp&minus;1&sol;10&ast;t&Hat;2&comma;t&equals;0..xend ifend proc


Note that the procedure is set up for an unevaluated return if the input is not numeric.





Error, (in `dsolve/numeric/DAE/make_proc`) number of unknown functions and equations must match, got 2 functions {f, y}, and 1 equations

This failed because 'known' was not specified. Here, it is specified.


dsol8:=procx_rkf45...end proc








A method that requires derivatives,


Error, (in `dsolve/numeric/checkknown`) use of 'rosenbrock' method with procedure defined function f requires a differentiation rule `diff/f`

which failed because a differentiation rule is required. We then clear the remember table of diff and define this as:


`diff/f` := proc()
    # Chain rule
end proc:

which works as follows:







and now:


dsol8b:=procx_rosenbrock...end proc








See Also

Digits, dsolve/dae_extension, dsolve/Error_Control, dsolve[ck45], dsolve[classical], dsolve[dverk78], dsolve[Events], dsolve[gear], dsolve[interactive], dsolve[lsode], dsolve[maxfun], dsolve[mebdfi], dsolve[numeric,BVP], dsolve[numeric,DAE], dsolve[numeric,interactive], dsolve[numeric,IVP], dsolve[rkf45], dsolve[rosenbrock], dsolve[Stiffness], dsolve[taylorseries], fsolve, interface, plots[odeplot]



Ascher, U.; Mattheij, R.; and Russell, R. "Numerical Solution of Boundary Value Problems for Ordinary Differential Equations." SIAM Classics in Applied Mathematics. Vol. 13. (1995).


Ascher, U., and Petzold, L. "Computer Methods for Ordinary Differential Equations and Differential-Algebraic Equations." SIAM, Philadelphia. 1998.


Bailey, P.B.; Shampine, L.F.; and Waltman, P.E. Nonlinear Two Point Boundary Value Problems. New York: Academic Press, 1968.


Boyce, W.E., and DiPrima, R.C. Elementary Differential Equations and Boundary Value Problems. New York: John Wiley & Sons, 1997.


Cash, J.R. "The Integration of Stiff IVP in ODE Using Modified Extended BDF." Computers and Mathematics with Applications. Vol. 9. (1983): 645-657.


Gear, C.W. Numerical Initial Value Problems in Ordinary Differential Equations. Prentice-Hall, 1971.


Hindmarsh, Alan C.; Stepleman, R.S.; et al, eds. Odepack, a Systemized Collection of ODE Solvers. Amsterdam: North-Holland, 1983.


Hubbard J.H., and West, B.H. Differential Equations: A Dynamical Systems Approach. New York: Springer, 1990. Part I. One Dimensional Equations.


Hull, T.E.;  Enright, W.H.; Fellen, B.M.; and Sedgwick, A.E. "Comparing Numerical Methods for Ordinary Differential Equations." SIAM J. Numer. Anal. Vol. 9. (1972): 603-637.


Shampine, L.F., and Corless, R.M. "Initial Value Problems for ODEs in Problem Solving Environments." J. Comp. Appl. Math. Vol. 125(1-2). (2000): 31-40.

Download Help Document

Was this information helpful?

Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam