Sie sind auf Seite 1von 36

dsolve/numeric/DAE - find numerical solution of differential-algebraic initial

value problems

Calling Sequence
dsolve(daesys, numeric, vars, options)

Parameters
daesys - set or list; ordinary differential equation(s), algebraic equation(s) and
initial conditions
numeric -

name; instruct dsolve to find a numerical solution

vars

(optional) dependent variable or a set or list of dependent variables for

daesys
options -

(optional) equations of the form keyword = value

Description

The dsolve command with the numeric or type=numeric option and a real-valued
differential-algebraic initial value problem (DAE IVP) finds a numerical solution for
the DAE IVP. If the optional equation method=numericmethod is provided (where
numericmethod is one of rkf45_dae, rosenbrock_dae, or mebdfi, dsolve uses that
method to obtain the numerical solution.
In most cases dsolve is able to detect if the problem is a DAE system, as opposed to
an ODE system, namely the cases in which pure algebraic equations in the dependent
variables are present. If the input is a DAE system containing no purely algebraic
equations, the method must be included to specify that the system is a DAE system.
Constrained mechanical systems often give rise to DAE problems. (See the pendulum
example below.)
The return value of dsolve and the following high level or common options are
discussed in dsolve[numeric] and dsolve[Error_Control].
'output'

keyword or array

'range'

numeric..numeric

'abserr'

numeric or list

'relerr'

numeric

'stiff'

boolean

'known'

name or list of names

'optimize' =

boolean

The exception is that for the DAE solvers the absolute error tolerance can be specified
as a per-component list. For expected behavior, the variables of the problem must also
be specified as a list, and the entries of 'abserr' must correspond 1-1 to the variables
in the list, or to the variables in the system converted to first order using the order of
the variables in the list. For more information, see the ?dsolve[numeric,IVP] help
page.
The default DAE IVP method is a modified Runge-Kutta Fehlberg method, which
uses a base order 4-5 method, but has been modified to find solutions for DAE
problems. The default stiff method is a Rosenbrock method, which uses a base order
3-4 method. For a description of the modifications done to these methods in
extending them to DAE solution, see the ?dae_extension help page. The other method
available for DAE IVP is the dsolve[mebdfi] method, which is short for Modified
Extended Backward-Differentiation Formula Implicit method.
In general, the DAE IVP solvers are very similar to the standard differential IVP
solvers, so this page is primarily concerned with outlining the differences between
them.
The DAE solvers are currently restricted to finding solutions for real-valued
problems.
For use of any of the methods, the specified initial conditions must satisfy all hidden
constraints of the system (that is, they must be a consistent set of initial conditions
with respect to the DAE). In the event that they do not, an error results, and
information is provided on the unsatisfied condition.
In some cases, it may be necessary to use fsolve to compute consistent initial
conditions for the problem.
If the ?dae_extension methods are in use, the differential option is set to true, and the
system is sufficiently linear in the algebraic variables (i.e., variables which have no
derivatives appearing in the input system), it is possible to skip initial conditions for
those variables. If the initial conditions are skipped when they are required, an error
will be produced.
The following options are also available for some or all of the DAE methods:
'minstep'

numeric

'maxstep'

numeric

'initstep'

numeric

'startinit'

boolean

'events'

list

'event_pre'

keyword

'event_maxiter' =

integer

'projection'

boolean

'differential'

boolean

'implicit'

boolean

'parameters'

list of names

'minstep', 'maxstep', and 'initstep'


These options are discussed in dsolve[Error_Control], and are only available for the
dsolve[mebdfi] method.
'startinit'= boolean
This option controls the behavior of the numerical integration with respect to
consecutive calculations. This option is described in dsolve[numeric,IVP].
For the default methods, rkf45_dae and rosenbrock_dae, when a 'range' has been
specified, the solution is recomputed only when the new value of the independent
variable is not between the initial point and any other previously requested solution
point. This has the effect of never reversing the direction of integration, and making
evaluation of the solution for an already computed interval quite inexpensive (the
solution values are obtained by interpolation). The storage of the solution can also be
enabled by using the storage argument. The startinit parameter also forces these
methods to recompute the solution whenever a solution value is desired.
'events'= list
'event_pre'= keyword
'event_maxiter'= integer
These options are available only for the rkf45_dae and rosenbrock_dae methods, and
are used to specify and control the behavior of events. These are the same as for
standard IVP problems. For a description, see the ?dsolve[numeric,IVP] and ?
dsolve[Events] help pages.
'projection', 'differential', and 'implicit'
The 'projection', 'differential' and 'implicit' options are specific to the extension
methods, so they are discussed there.
In addition to the computation of solution values for the given input problem, the
procedure returns (that is, output=procedurelist, listprocedure or operator) provide
additional interactive features, including the ability to specify parameters.
Information on these features is provided on the dsolve[numeric,interactive] page.
The exception is that the mebdfi method cannot work with parametrized problems.

Examples
As a first example, we consider the problem of modeling the dynamics of a mass on a
string of unit length in 2-D Cartesian coordinates (the pendulum problem). We let r be
the position of the mass on the string, and v the velocity:
> VectorCalculus[SetCoordinates](cartesian):
> VectorCalculus[BasisFormat](false):
> r := VectorCalculus[Vector]([x(t),y(t)]);
3

x( t )

y( t )

r :=

> v := VectorCalculus[diff](r,t);
d x( t )
dt

v :=

y
(
t
)
dt

Since the mass is on a string of fixed length l, we have the constraint:


> con := VectorCalculus[DotProduct](r,r)-l^2;
con := x( t )2y( t )2l2

Now we want to construct the DAE system using the Euler-Lagrange formulation, so we
compute the kinetic energy T and the potential energy V as:
> T := m/2*VectorCalculus[DotProduct](v,v);
1
T := m
2

d x( t ) d y( t )
dt

dt

> V := m*g*y(t);
V := m g y( t )

where m is the mass, and g is the gravitational constant (we will use 9.8). The Lagrangian
and modified Lagrangian are given by:
> L := T-V;
1
L := m
2

d x( t ) d y( t )
dt

dt

m g y( t )

> ML := L - lambda(t)*con;
1
ML := m
2

d x( t ) d y( t )
dt

dt

2
2
2
m g y( t )( t ) ( x( t ) y( t ) l )

We can then construct the Euler-Lagrange formulation via:


> Q := remove(has,VariationalCalculus:-EulerLagrange(
ML,t,[x(t),y(t),lambda(t)]),K);
4

d2

d2

2
2
2
x
(
t
)
,

x
(
t
)

y
(
t
)

l
,

m
g

(
t
)
y
(
t
)

m
y( t ) }
2
2

dt

dt

Q := { 2 ( t ) x( t )m

> EQx := isolate(select(has,Q,diff(x(t),t,t))


[1],diff(x(t),t,t));
EQx:=

d2
( t ) x( t )
x( t )2
2
m
dt

> EQy := isolate(select(has,Q,diff(y(t),t,t))


[1],diff(y(t),t,t));
EQy:=

d2
m g2 ( t ) y( t )
2 y( t )
m
dt

> EQc := remove(has,Q,diff)[1];


EQc:= x( t )2y( t )2l2

Now we have the equations of motion for the pendulum. Next, we need to determine
consistent initial conditions. To do so, we must identify any hidden constraints of the
system. These are easy to find, as we have only one constraint.
> Dcon := diff(EQc,t);
d
d
x( t ) 2 y( t ) y( t )
d
t
d

Dcon:= 2 x( t )

> DDcon := eval(diff(Dcon,t),{EQx,EQy});


2

d
x( t )2 ( t )
d
y( t ) ( m g2 ( t ) y( t ) )
x( t ) 4
2 y( t ) 2
d
t
m
d
t
m

DDcon:= 2

Our initial conditions must satisfy EQc, Dcon, and DDcon at the initial point, leaving
only 2 degrees of freedom for the conditions. So for a pendulum starting at the minimum
value of y(0) = -l having an initial horizontal velocity of D(x)(0) = vx, we get:
> sys := {y(0)=-l,D(x)(0)=vx} union
eval(convert({EQc,Dcon,DDcon},D),t=0);
sys := { 2 x( 0 ) D( x )( 0 )2 y( 0 ) D( y )( 0 ), x( 0 )2y( 0 )2l2,
2 D( x )( 0 )24

x( 0 )2 ( 0 )
y( 0 ) ( m g2 ( 0 ) y( 0 ) )
2 D( y )( 0 )22
, y( 0 )l,
m
m

D( x )( 0 )vx}

> ini := [solve(sys,{x(0),y(0),D(x)(0),D(y)(0),lambda(0)})]


[1];
1 m ( vx2l g )
ini := { ( 0 )
, x( 0 )0, y( 0 )l, D( x )( 0 )vx, D( y )( 0 )0 }
2
l2

So we consider the above with a pendulum of unit length l = 1 having unit mass m = 1
and an initial horizontal velocity of vx = 1/10, giving us the DAE system and initial
conditions:
> dsys := eval({EQx,EQy,EQc},{l=1,m=1,g=9.8,vx=1/10});
dsys := { x( t )2y( t )21,

d2
d2
x
(
t
)

(
t
)
x
(
t
)
,
y( t )9.82 ( t ) y( t ) }
dt2
dt2

> dini := eval(ini,{l=1,m=1,g=9.8,vx=1/10});


1
dini := { ( 0 )4.905000000
, x( 0 )0, y( 0 )-1, D( x )( 0 ) , D( y )( 0 )0 }
10

We can then obtain the solution as:


> dsol1 := dsolve(dsys union dini, numeric);
dsol1:= proc(x_rkf45_dae
) ... end proc

> dsol1(1/2);
t0.500000000000000
, ( t )4.89750023744205887
, x( t )0.0319392547405407887
,

d
x( t )0.000564531449666508191
, y( t )-0.999489811893806701
,
dt
d

y( t )0.0000180382736946334369

dt

> dsol1(1);

t1., ( t )4.90499904949563259
, x( t )0.000360893004470803490
,

d
x( t )-0.0999936779200488873
, y( t )-0.99999993487231431
,
dt
d

y( t )-0.0000360870084253994927

dt

Solution with rosenbrock_dae:


> dsol2 := dsolve(dsys union dini, numeric,
method=rosenbrock_dae);
dsol2:= proc(x_rosenbrock_dae
) ... end proc

> dsol2(1/2);
t0.500000000000000
, ( t )4.89750019118586088
, x( t )0.0319392364763693773
,

d
x( t )0.000564626004686089771
, y( t )-0.999489813543333439
,
dt
d

y( t )0.0000180482728717063205

dt

> dsol2(1);
t1., ( t )4.90499906207810721
, x( t )0.000360968463263104937
,

d
x( t )-0.0999936779452163804
, y( t )-0.99999993669131815
,
dt
d

y( t )-0.0000360897908606885759

dt

Solution with mebdfi:


> dsol3 := dsolve(dsys union dini, numeric, method=mebdfi);
dsol3:= proc(x_mebdfi) ... end proc

> dsol3(1/2);
t0.500000000000000
, ( t )4.89750245194350509
, x( t )0.0319388403694855147
,

d
x( t )0.000564871203422257005
, y( t )-0.999489825189509129
,
dt
d

y( t )0.0000180670454630691393

dt

> dsol3(1);

t1., ( t )4.90497944724429935
, x( t )0.000361097312194549836
,

d
x( t )-0.0999925039194764775
, y( t )-0.99999993426187950
,
dt
d

y( t )-0.0000359881610159317974

dt

Now consider a similar problem as above, but in addition add a second mass supported
from the first by another string, this one of length 1/2 (the double pendulum). The system
can be obtained and solved as:
> dsysd := {
diff(x1(t),t,t)
+2*lambda1(t)*x1(t)
+2*lambda2(t)*(x1(t)-x2(t)),
diff(y1(t),t,t)+9.8+2*lambda1(t)*y1(t)
+2*lambda2(t)*(y1(t)-y2(t)),
diff(x2(t),t,t)
-2*lambda2(t)*(x1(t)-x2(t)),
diff(y2(t),t,t)+9.8
-2*lambda2(t)*(y1(t)-y2(t)),
x1(t)^2+y1(t)^2-1,
(x1(t)-x2(t))^2+(y1(t)-y2(t))^2-1/4
};
1
d2

x2( t ) 2 ( t ) ( x1( t )x2( t ) ), ( x1( t )x2( t ) )2( y1( t )y2( t ) )2 ,


2
dt
4

dsysd:= {

d2

x1( t ) 2 ( t ) x1( t )2 ( t ) ( x1( t )x2( t ) ),


dt2

x1( t )2y1( t )21,

d2

dt2 y2( t ) 9.82 ( t ) ( y1( t )y2( t ) ),

d2

dt2 y1( t ) 9.82 ( t ) y1( t )2 ( t ) ( y1( t )y2( t ) ) }

> ics := {x1(0)=0,D(x1)(0)=-3,y1(0)=-1,D(y1)(0)=0,


x2(0)=0,D(x2)(0)=4,y2(0)=-3/2,D(y2)(0)=0};
8

-3
ics := { x1( 0 )0, x2( 0 )0, y1( 0 )-1, y2( 0 ) , D( x1)( 0 )-3, D( x2)( 0 )4, D( y1)( 0 )0,
2
D( y2)( 0 )0}

> dsold := dsolve(dsysd union ics,numeric);


dsold:= proc(x_rkf45_dae
) ... end proc

The trajectory of the second mass can be plotted via:


> plots[odeplot](dsold,[x2(t),y2(t)],0..5,numpoints=1000);
Note that we did not specify initial conditions for lambda1(t) and lambda2(t) as we
were using an extension method, and the system was sufficiently linear in the lambda.

See Also
dsolve/dae_extension, dsolve/Error_Control, dsolve[Events], dsolve[maxfun],
dsolve[mebdfi], dsolve[numeric,interactive], dsolve[numeric,IVP], dsolve[numeric],
dsolve[rkf45], dsolve[rosenbrock], dsolve[Stiffness], plots[odeplot]

dsolve/numeric - find numerical solution of ordinary differential equations


Calling Sequence
dsolve(odesys, numeric, vars, options)
dsolve(numeric, procopts, options)

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

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
vars

procopts - (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].
options

(optional) equations of the form keyword = value

Description

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,

rosenbrock, bvp, rkf45_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 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.

Options

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

= keyword or array

'stiff'

= boolean

'events'

= list

'event_pre'

= keyword

'event_maxiter' = integer
'range'

= numeric..numeric

'abserr'

= numeric or list

'relerr'

= numeric

'known'

= name or list of names

'optimize'

= boolean

10

'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,
[result](1)).
The piecewise keyword is available only for non-stiff and stiff default IVP and DAE
methods (rkf45, rosenbrock, rkf45_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.

11

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 default methods, rkf45, rosenbrock, rkf45_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 default methods
(rkf45, rosenbrock, rkf45_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.
Notes:
- 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* 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.

12

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*, 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 default non-stiff rkf45 method 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.

13

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.

Notes

When Digits<=evalhf(Digits), 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>evalhf(Digits) 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, 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.

Examples
Set of dependent variables specified as a list.
> dsys := {diff(x(t),t)=y(t),diff(y(t),t)=x(t),x(0)=1,y(0)=0}: #default alphabetical
> dsn1 := dsolve(dsys,numeric):

14

> dsn1(1);
[ t1., x( t )0.540302331775852962
, y( t )-0.841471101157619694
]

> [t = 1., x(t) = 0.540302304342753614, y(t) =


-0.841471136025939148];
[ t1., x( t )0.540302304342753614
, y( t )-0.841471136025939148
]

> dsn2 := dsolve(dsys,numeric,[y(t),x(t)]): # specify


differently
> dsn2(1);
[ t1., y( t )-0.841471101157619694
, x( t )0.540302331775852962
]

> [t = 1., y(t) = -0.841471136025939148, x(t) =


0.540302304342753614];
[ t1., y( t )-0.841471136025939148
, x( t )0.540302304342753614
]

Straightforward second order IVP:


> deq1

:= (t+1)^2*diff(y(t),t,t) + (t+1)*diff(y(t),t)
+ ((t+1)^2-0.25)*y(t) = 0;
d
d2

y( t ) ( t1 ) y( t ) ( ( t1 )20.25) y( t )0
2
dt
dt

deq1:= ( t1 )2

> ic1

:= y(0) = 0.6713967071418030,
D(y)(0) = 0.09540051444747446:

> dsol1 := dsolve({deq1,ic1}, numeric, range=0..1);


dsol1:= proc(x_rkf45) ... end proc

> dsol1(0);
d
t0., y( t )0.671396707141803

, y( t )0.0954005144474745

dt

> dsol1(0.5);
d
t0.5, y( t )0.649838013736888986

, y( t )-0.170529562812813923

dt

15

> dsol1(1);
d
t1., y( t )0.513016090104812750

, y( t )-0.363039820324437268

dt

Same second order IVP with operator output:


> dsol1b := dsolve({deq1,ic1}, numeric, output=operator);
dsol1b:= [ t( proc(t) ... end proc), y( proc(t) ... end proc), D( y )( proc(t) ... end proc) ]

> dsol1b(0);
[ t0., y( 0 )0.671396707141803
, D( y )( 0 )0.0954005144474745
]

> dsol1b(0.5);
[ t0.5, y( 0.5)0.649838013736888986
, D( y )( 0.5)-0.170529562812813923
]

> dsol1b(1);
[ t1., y( 1 )0.513016090104812750
, D( y )( 1 )-0.363039820324437157
]

First order IVP:


> dsol2 := dsolve({diff(y(x),x) = y(x)*cos(x), y(0) = 1},
numeric, output=listprocedure);
dsol2:= [ x( proc(x) ... end proc), y( x )( proc(x) ... end proc) ]

> fy2 := eval(y(x),dsol2);


fy2 := proc(x) ... end proc

> [fy2(0), fy2(Pi/4), fy2(Pi/2), fy2(3*Pi/2), fy2(Pi)];


[ 1., 2.02811545714854358
, 2.71828201727134067
, 0.367879858344611010
, 0.99999978584906291
]

First order IVP with piecewise output:


> dsol2p := dsolve({diff(y(x),x) = y(x)*cos(x), y(0) = 1},
numeric, output=piecewise, range=0..1);

16

dsol2p:= [ xx, y( x ){ undefined, x0.


0.9996148585926321.02775126621618

x0.499406940429397
( x0.0277621231571284
)2
0.0145000345534934
( x0.0277621231571284
)3
0.133835295525126
( x0.0277621231571284
)4 , x0.0555242463142568005

0.9891015521303121.14719850212164

x0.481091117077175
( x0.149013262847986
)2
0.0904918749076433
( x0.149013262847986
)3
0.172313265605643
( x0.149013262847986
)4 , x0.242502279381714925
0.9483974661047881.31597042276291

x0.387428683672683
( x0.340057388023573
)2

0.244571952691719
( x0.340057388023573
)3
0.220713724711619
( x0.340057388023573
)4 , x0.437612496665429673
0.8974252168155321.43475629978265

x0.183288214134115
( x0.541367533479570
)2
0.432634746414217
( x0.541367533479570
)3

0.225886958082298
( x0.541367533479570
)4 , x0.645122570293710451
0.890827299363461.44839243200460

x0.133255972486488
( x0.743628540879176
)2
0.598745668467567
( x0.743628540879176
)3
0.155195536908010
( x0.743628540879176
)4 , x0.842134511464641689

0.981744432890901.34133782274070

x0.477242160985022
( x0.921067255732321
)2
0.673533874998910
( x0.921067255732321
)3
0.0140365572679978
( x0.921067255732321
)4 , x1.
undefined, otherwise]

Stiff nonlinear problem:


> dsys3 := diff(x(t),t) = x(t)^2 - t^6, x(0)=-0.1;
dsys3:=

d
x( t )x( t )2t6, x( 0 )-0.1
dt

> dsol3 := dsolve([dsys3], type=numeric, stiff=true,


output=array([0,0.25,0.5,0.75,1]));
17

[ t, x( t ) ]


0.
-0.100000000000000006



0.250000000000000000-0.0975697047501167536

dsol3:=

0.500000000000000000-0.0963407325327339248

0.750000000000000000-0.111744790112399378



1.
-0.229279026435938033

Linear BVP:
> dsol4 := dsolve([diff(y(x),x,x) = 3*y(x),
y(0) = 1, y(2) = 1.2], numeric);
dsol4:= proc(x_bvp) ... end proc

> dsol4(0);
d
x0., y( x )0.99999999999999956

, y( x )-1.60520425463385008

dx

> dsol4(0.5);
d
x0.5, y( x )0.492273627127113922

, y( x )-0.551072761778112929

dx

> dsol4(1);
d
x1., y( x )0.377412857949489755

, y( x )0.0632677085684644064

dx

> dsol4(2);
d
x2., y( x )1.20000000000000129

, y( x )1.97400119243652483

dx

Nonlinear BVP:
> dsys5 := {diff(y(x),x,x) + abs(y(x)) = 0, D(y)(0) = 1,
y(1) = -1};
d2

y( x ) y( x ) 0, y( 1 )-1, D( y )( 0 )1 }
dx2

dsys5:= {

> dsol5 := dsolve(dsys5, numeric,


output=array([0,0.25,0.5,0.75,1]));

18

x, y( x ), d y( x )

dx
0. -1.40964842958752423 1.00000000000000044


dsol5:= 0.25 -1.201317539681559190.675318544177146429


0.5 -1.068460865510630690.393064786112398645

0.75 -1.002731527130149350.135505794809609836

1. -0.99999999999999989-0.113539882361525873

DAE:
> dsys6:= {
diff(x(t),t,t) = -2*lambda(t)*x(t),
diff(y(t),t,t) = -2*lambda(t)*y(t)-Pi^2,
x(t)^2+y(t)^2 = 1,
x(0)=0, D(x)(0)=1/10, y(0)=-1, D(y)(0)=0};
dsys6:= { x( t )2y( t )21,

d2
d2
2
x
(
t
)

(
t
)
x
(
t
)
,
2
2 y( t )2 ( t ) y( t ) , x( 0 )0, y( 0 )-1,
dt
dt

1
D( x )( 0 ) , D( y )( 0 )0 }
10

> dsol6 := dsolve(dsys6, numeric);


dsol6:= proc(x_rkf45_dae
) ... end proc

> dsol6(1);
t1., ( t )4.93980220700398576
, x( t )0.633673384333266021
10-5,

d
x( t )-0.100000064975738170
, y( t )-0.99999999997887001
,
dt
d
y( t )-0.633673070599169403
10-6
dt

Use with fsolve:


> dsys7 := {diff(y(x),x)=2*y(x), y(0)=1};
dsys7:= {

d
y( x )2 y( x ), y( 0 )1 }
dx

19

> Digits := 20;


Digits:= 20

> dsol7 := dsolve(dsys7, numeric, method=gear, abserr=1e-16,


relerr=1e-16,
output=listprocedure);
dsol7:= [ x( proc(x) ... end proc), y( x )( proc(x) ... end proc) ]

> yproc := rhs(dsol7[2]);


yproc:= proc(x) ... end proc

Attempt with same Digits setting, returns unevaluated.


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

The same command with Digits set to 15 succeeds.


> Digits := 15;
Digits:= 15

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


5.75646273248511

> Digits := 10;


Digits:= 10

Use of known option:


> f := proc(x) local t;
if not type(evalf(x),'numeric') then
'procname'(x);
else
evalf(Int(exp(-t^2/10),t=0..x));
end if;

20

end proc;
f := proc(x)
local t;
if not type( evalf( x ), 'numeric' ) then'procnamex
'( ) end proc
else evalf( Int( exp( 1/10t^2 ), t0 .. x ) )
end if

Note that the procedure is set up for an unevaluated return if the input is not numeric.
> dsys8 := {diff(y(x),x)=y(x)+f(x), y(0)=0};
dsys8:= {

d
y( x )y( x )f( x ), y( 0 )0 }
dx

> dsolve(dsys8, 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 := dsolve(dsys8, numeric, known=f);
dsol8:= proc(x_rkf45) ... end proc

> dsol8(1);
[ x1., y( x )0.708149294799616413
]

> dsol8(2);
[ x2., y( x )4.19167993111609594
]

A method that requires derivatives,


> dsolve(dsys8, numeric, method=rosenbrock, known=f);
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:
> forget(diff);
> `diff/f` := proc()
# Chain rule
21

diff(args[1],args[2])*exp(-(args[1])^2/10);
end proc:
which works as follows:
> diff(f(sin(x)),x);
cos( x ) e

( 1/10 sin( x )2 )

> diff(Int(exp(-t^2/10),t=0..sin(x)),x);
cos( x ) e

2
( 1/10 sin( x ) )

and now:
> dsol8b := dsolve(dsys8, numeric, method=rosenbrock,
known=f);
dsol8b:= proc(x_rosenbrock
) ... end proc

> dsol8b(1);
[ x1., y( x )0.708149269188471653
]

> dsol8b(2);
[ x2., y( x )4.19168036703642688
]

See Also
Digits, dsolve/dae_extension, dsolve/Error_Control, 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]

References
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.

22

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.

dsolve/numeric/classical - numerical solution of ordinary differential


equations

Calling Sequence
dsolve(odesys, numeric, method=classical)
dsolve(odesys, numeric, method=classical[choice], vars, options)
dsolve(numeric, method=classical[choice], procopts, options)

Parameters
odesys

set or list; ordinary differential equation(s) and

literal name; instruct dsolve to find a numerical

literal equation; numerical method to use

initial conditions
numeric

solution
method=classical

method=classical[choice] -

equation; numerical method and submethod to use

vars

(optional) dependent variable or a set or list of

(optional) equations of the form keyword = value

dependent variables for odesys


options

options used to specify the ODE system using a


procedure (procedure, initial, start, number, and procvars). For more information, see
dsolve[numeric,IVP].
procopts

23

Description

The dsolve command with the options numeric and method=classical or


method=classical[choice] finds a numerical solution by using one of the classical
numerical methods as described in the following.
These methods use a fixed step size, provide no error estimation or correction, and are
provided primarily for educational purposes. If practical numerical solution of ODE
initial value problems (IVP) is required, it is suggested that any of the other methods
mentioned in dsolve[numeric,IVP] help page be used instead.
A number of classical methods are available through use of the choice option in the
method=classical[choice] selection. The default is foreuler, the forward Euler
method.
The available choices of the classical method are described for the problem y'=f(t,y),
where Y[i] is the estimated value of the solution at the time t[i], h is the fixed step
size t[i]-t[i-1], and for each formula the value of the solution Y[n+1] at time t[n+1] is
being computed.
foreuler is the forward Euler method specified by the equation:
Y[n+1] = Y[n] + h*f(t[n], Y[n])

heunform is the Heun formula (also known as the improved Euler method). It uses
the forward Euler method to predict the solution, and then applies the trapezoid rule
as a corrector. It is specified by the pair of equations:
Yp

= Y[n] + h*f(t[n], Y[n])

Y[n+1] = Y[n] + (h/2)*(f(t[n],Y[n]) + f(t[n+1],Yp))

impoly is the improved polygon method (also known as the modified Euler method),
as specified by the equation:
Y[n+1] = Y[n] + h*(f(t[n]+h/2, Y[n]+(h/2)*f(t[n],Y[n])))

rk2 is the second-order classical Runge-Kutta method, as specified by:


k1

= f(t[n], Y[n])

k2

= f(t[n]+h, Y[n]+h*k1)

Y[n+1] = Y[n] + (h/2)*(k1+k2)

Note: This is the same as the Heun formula.


rk3 is the third-order classical Runge-Kutta method, as specified by:
k1

= f(t[n], Y[n])

k2

= f(t[n]+(h/2), Y[n]+(h/2)*k1)

k3

= f(t[n]+h, Y[n]+h*(-k1+2*k2))

Y[n+1] = Y[n] + (h/6)*(k1+4*k2+k3)

24

rk4 is the fourth-order classical Runge-Kutta method, as specified by:


k1

= f(t[n], Y[n])

k2

= f(t[n]+h/2, Y[n]+(h/2)*k1)

k3

= f(t[n]+h/2, Y[n]+(h/2)*k2)

k4

= f(t[n]+h, Y[n]+h*k3)

Y[n+1] = Y[n] + (h/6)*(k1+2*k2+2*k3+k4)

This is not to be confused with method=rkf45, which uses a Fehlberg fourth-fifth


order Runge-Kutta method.
adambash is the Adams-Bashforth method (a predictor method), as specified by:
Y[n+1] = Y[n] + (h/24) * (55*f(t[n],Y[n]) - 59*f(t[n-1],Y[n-1])
+ 37*f(t[n-2],Y[n-2]) - 9*f(t[n-3],Y[n-3]))

abmoulton is the Adams-Bashforth-Moulton method (a predictor-corrector method),


as specified by:
Y[n+1] = Y[n] + (h/24) * (9*f(t[n+1],Y[n+1]) + 19*f(t[n],Y[n])
- 5*f(t[n-1],Y[n-1]) + f(t[n-2],Y[n-2])),

where f(t[n+1],Y[n+1]) is found by first applying the Adams-Bashforth method (the


predictor), then using the above Adams-Bashforth-Moulton method (the corrector).
The following options are available for the classical method:
'output'

keyword or array

'known'

name or list of names

'maxfun'

integer

'number'

integer

'procedure'

procedure

'start'

numeric

'initial'

array

'procvars'

list

'startinit'

boolean

'implicit'

boolean

'optimize'

boolean

'stepsize'

numeric

25

'corrections' =

integer

'output'
Specifies the desired output from dsolve, and the known option specifies userdefined known functions. For more information, see dsolve[numeric].
'maxfun'
Specifies a maximum on the number of evaluations of the right-hand side of the first
order ODE system. This option can be disabled by specifying maxfun=0. The default
value for classical methods is 50000. For more information, see dsolve[maxfun].
'number', 'procedure', 'start', 'initial', and 'procvars'
These options are used to specify the IVP using procedures. For more information,
see dsolve[numeric,IVP].
'startinit','implicit', and 'optimize'
These options control the method and behavior of the computation. For more
information on the first two, see dsolve[numeric,IVP], for the last, see
dsolve[numeric].
'stepsize'
Specifies the static size of each step. Note that classical does not use error correction
estimates to adapt the step size. The default step size is h = min((T0-Tf)/3, 0.005) for
forward integration and h = max((T0-Tf)/3, -0.005) for backward integration,
respectively, where the problem is solved over the interval from T0 to Tf.
'corrections'
A positive integer that specifies the number of corrections that should be applied for
the abmoulton method at each step. It is recommended that this number not exceed 4
(values greater than 4 generally do not produce more accurate results, and result in
longer running times).

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

Examples
> dsys1 := diff(y(t),t$3) = y(t)+diff(x(t),t),
diff(x(t),t$2) = x(t)*y(t)-diff(y(t), t$2);
dsys1:=

2
2
d3
d x( t ) , d x( t )x( t ) y( t ) d y( t )
y
(
t
)

y
(
t
)

dt
dt2
dt2

dt3

26

> init1 := y(0) = 1, D(y)(0) = 2, (D@@2)(y)(0) = -1,


x(0) = 4, D(x)(0) = 4.3;
( 2)

init1:= y( 0 )1, D( y )( 0 )2, ( D )( y )( 0 )-1, x( 0 )4, D( x )( 0 )4.3

> ans1 := dsolve({dsys1,init1}, numeric,


method=classical[abmoulton], corrections=2);
ans1:= proc(x_classical
) ... end proc

> ans1(1.0);

d
, x( t )18.7876915350014215
,
t1.0, x( t )13.1246093792715683
dt

d
d2
y( t )3.76283413230601260
, y( t )5.31760397608216362
, 2 y( t )10.2504683623596353
dt
dt

> deq2 := diff(y(x), x$2) = y(x);


deq2:=

d2
y( x )y( x )
dx2

> init2 := y(0) = 1, D(y)(0) = 1;


init2:= y( 0 )1, D( y )( 0 )1

> Digits := 20:


ans2 := dsolve({deq2, init2}, numeric,
method=classical[heunform],
output=array([0.01,0.1,1]),
stepsize=0.001);

27

x, y( x ), d y( x )

dx

ans2:= 0.01 1.01005016540201317151.0100501654020131715





0.1 1.10517089966994158801.1051708996699415880


1. 2.71828137575176083992.7182813757517608399

> Digits := 10:


deq3

:= { diff(y(t),t$4) - diff(y(t),t$3) = y(t)*t^2 };


d4
d3

2
y
(
t
)
dt3 y( t ) y( t ) t }
dt4

deq3:= {

> init3 := { y(0) = 3.56, D(y)(0) = 12, (D@@2)(y)(0) = -4,


(D@@3)(y)(0) = 6.544 };
( 2)

( 3)

init3:= { y( 0 )3.56, D( y )( 0 )12, ( D )( y )( 0 )-4, ( D )( y )( 0 )6.544}

> ans3 := dsolve(deq3 union init3, numeric,


method=classical[rk3], output=listprocedure):
sol3 := eval(y(t), ans3);
sol3 := proc(t) ... end proc

> sol3(0);
3.56

> sol3(0.56);
9.87504792480694960

See Also
dsolve[dverk78], dsolve[gear], dsolve[lsode], dsolve[maxfun], dsolve[numeric],
dsolve[numeric,IVP], plots[odeplot], dsolve[rkf45], dsolve[rosenbrock],
dsolve[taylorseries]

References
Boyce, W.E., and DiPrima, R.C. Elementary Differential Equations and Boundary
Value Problems. 5th ed. New York: Wiley, 1992.
Conte, S.D., and C. de Boor. Elementary Numerical Analysis, An Algorithmic
Approach. McGraw-Hill, 1980.

28

Fox, L., and Mayers, D.F. Numerical Solution of Ordinary Differential Equations
for Scientists and Engineers. Chapman & Hall, 1987.
Lambert, J.D. Computational Methods in Ordinary Differential Equations. New
York: Wiley, 1973.

dsolve/numeric/rkf45 - find numerical solution of ordinary differential


equations

Calling Sequence
dsolve(odesys, numeric, method=rkf45, vars, options)
dsolve(numeric, method=rosenbrock, procopts, options)

Parameters
odesys

set or list; ordinary differential equation(s) and initial conditions

numeric

literal name; instruct dsolve to find a numerical solution

method=rkf45 -

literal equation; numerical method to use

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

(optional) equations of the form keyword = value

options used to specify the ODE system using a procedure


(procedure, initial, start, number, and procvars). For more information, see
dsolve[numeric,IVP].
procopts

Description

The dsolve command with the options numeric and method=rkf45 finds a numerical
solution using a Fehlberg fourth-fifth order Runge-Kutta method with degree four
interpolant. This is the default method of the type=numeric solution for initial value
problems when the stiff argument is not used.

Modes of Operation

The rkf45 method has two distinct modes of operation (for procedure-type outputs).

With the range option


When used with the range option, the method computes the solution for the IVP over
the specified range, storing the solution information internally, and uses that
information to rapidly interpolate the desired solution value for any call to the
returned procedure(s).
Though possible, it is not recommended that the returned procedure be called for
points outside the specified range.

29

This method can be used in combination with the refine option of odeplot to produce
an adaptive plot (that is, odeplot uses the precomputed points to produce the plot
when refine is specified.)
It is not recommended that this method be used for problems in which the solution
can become singular, as each step is stored, and many steps may be taken when near a
singularity, so memory usage can become a significant issue.
The storage of the interpolant in use by this method can be disabled by using the
interpolation=false option described below. This is recommended for high accuracy
solutions where storage of the interpolant (in addition to the discrete solution)
requires too much memory. Disabling the interpolant is not generally recommended
because the solution values are obtained from an interpolation of the 5 closest points,
and does not necessarily provide an interpolant with order 4 error.
Without the range option
When used without the range option, the IVP solution values are not stored, but
rather computed when requested.
Because not all solution values are stored, computation must restart at the initial
values whenever a point is requested between the initial point and the most recently
computed point (to avoid reversal of the integration direction), so it is advisable to
collect solution values moving away from the initial value.

Options

The following options are available for the rkf45 method.


'output'

keyword or array

'known'

name or list of names

'abserr'

numeric

'relerr'

numeric

'initstep'

numeric

'interr'

boolean

'maxfun'

integer

'number'

integer

'procedure'

procedure

'start'

numeric

'initial'

array

'procvars'

list

'startinit'

boolean

'implicit'

boolean

'optimize'

boolean

30

'compile'

boolean or 'auto'

'range'

numeric..numeric

'events'

list

'event_pre'

keyword

'event_maxiter' =

integer

'event_iterate' =

keyword

'event_initial' =

boolean

'complex'

boolean

output
Specifies the desired output from dsolve. The keywords procedurelist,
listprocedure, or operator provide procedure-type output, the keyword piecewise
provides output in the form of piecewise functions over a specified range of
independent variable values, and a 1-D array or Array provide output at fixed values
of the independent variable. For more information, see dsolve[numeric].
known
Specifies user-defined known functions. For more information, see dsolve[numeric].
abserr, relerr, and initstep
Specify the desired accuracy of the solution, and the starting step size for the method.
For more information, see dsolve[Error_Control]. The default values for rkf45 are
abserr = .1e-6 and relerr = .1e-5. The value for initstep, if not specified, is
determined by the method, taking into account the local behavior of the ODE system.
interr
By default this is set to true, and controls whether the solution interpolant error
(including the interpolant on index-1 variables for DAE problems) is integrated into
the error control. When set to false, areas where the solutions is varying rapidly (e.g.
a discontinuity in a derivative due to a piecewise) may have a much larger solution
error than dictated by the specified error tolerances. When set to true, the step size is
reduced to minimize error in these regions, but for problems where there is a jump
discontinuity in the variables, the integration may fail with an error indicating that a
singularity is present. In the latter case where an error is thrown, it may be
advantageous to model the discontinuities using events (see dsolve[Events]).
maxfun
Specifies a maximum on the number of evaluations of the right-hand side of the first
order ODE system. This option is disabled by specifying maxfun = 0. The default
value for rkf45 is 30000.
number, procedure, start, initial, and procvars
These options are used to specify the IVP using procedures. For more information,
see dsolve[numeric,IVP].
31

startinit, implicit, and optimize


These options control the method and behavior of the computation. For more
information on startinit and implicit, see dsolve[numeric,IVP]. For more information
on optimize, see dsolve[numeric].
compile
This option specifies that the internally generated procedures that are used to compute
the numeric solution be compiled for efficiency. Note that this option will only work
if Digits is set within the hardware precision range, and the input function contains
only evalhf capable functions (e.g. only elementary mathematical functions like exp,
sin, and ln). By default this value is set to false. If set to true and a compile is not
possible, an error will be thrown. If set to auto and a compile is not possible, the
uncompiled procedures will be used directly.
range
Determines the range of values of the independent variable for which solution values
are required. Use of this option significantly changes the behavior of the method for
the procedure-style output types discussed in dsolve[numeric] (see description of
with/without range in Modes of Operation section of this help page).
events, event_pre, event_maxiter, event_iterate, event_initial
These options are used to specify and control the behavior of events for the numerical
solution. These options are discussed in detail in dsolve[Events].
complex
Accepts a boolean value indicating if the problem is (or will become) complex
valued. By default this is detected based on the input system and initial data, but in
cases where the input system is procedure defined, or the system is initially real, it
may be necessary to specify complex=true to obtain the solution. It is assumed that
for an initially real system that becomes complex, the point at which this transition
occurs is considered to be a singularity, so if complex=true is not specified, the
integration will halt at that point.

Additional Information

By setting infolevel[dsolve] to 2, information on the last mesh point evaluation is


provided in the event of an error.
The rkf45 method is capable of computing high-accuracy solutions for IVPs because
the precision of the computation can be increased by changing the Digits environment
variable. However, it is recommended that the higher order dverk78 or gear methods
be used instead.
Results can be plotted by using the function odeplot in the plots package.

Examples
Solution with a range - solution over 0 .. 1 is stored:
> dsys1 := {diff(x(t),t)=y(t), diff(y(t),t)=x(t)+y(t),
x(0)=2, y(0)=1};

32

d
d
dsys1:= { x( t )y( t ), y( t )x( t )y( t ), x( 0 )2, y( 0 )1 }
dt
dt

> dsol1 := dsolve(dsys1, numeric, output=listprocedure,


range=0..1):
> dsol1x := subs(dsol1,x(t)): dsol1y := subs(dsol1,y(t)):
> [dsol1x(0), dsol1y(0)];
[ 2., 1. ]

> [dsol1x(0.4), dsol1y(0.4)];


[ 2.69118458493342860
, 2.60811748317278846
]

> [dsol1x(1.0), dsol1y(1.0)];


[ 5.58216753140402666
, 7.82688926499941573
]

Solution without a range - each point is computed when requested:


> dsol2 := dsolve(dsys1, numeric, method=rkf45,
output=procedurelist):
> dsol2(0);
[ t0., x( t )2., y( t )1. ]

> dsol2(0.4);
[ t0.4, x( t )2.69118458493342860
, y( t )2.60811748317278846
]

> dsol2(1.0);
[ t1.0, x( t )5.58216753140402577
, y( t )7.82688926499941395
]

array solution:
> dsys3 := {(D@@2)(x)(t)=-y(t), (D@@2)(y)(t)=D(x)(t)+y(t)};
( 2)

( 2)

dsys3:= { ( D )( x )( t )y( t ), ( D )( y )( t )D( x )( t )y( t ) }

> init3 := {x(0)=1, D(x)(0)=0, y(0)=0, D(y)(0)=1};


init3:= { x( 0 )1, y( 0 )0, D( x )( 0 )0, D( y )( 0 )1 }

33

> dsol3 := dsolve(dsys3 union init3, numeric, method=rkf45,


output=array([0,.6,1.1,1.5,2.3,2.5]));
dsol3:=
t, x( t ), d x( t ), y( t ), d y( t )

dt
dt
[
[ 0. , 1. , 0. , 0. , 1. ]

[ 0.599999999999999978
, 0.963412011936564228
, -0.184806440812177813
,
0.631128387721555550
, 1.14821845274874179
]
[ 1.10000000000000009
, 0.766914770923161404
, -0.654359851893226097
,
1.26996581973442213
, 1.42127462281638772
]
[ 1.50000000000000000
, 0.387748428237649434
, -1.28270433657142369
,

1.88843381066575611
, 1.67045276480907257
]
[ 2.29999999999999982
, -1.39457660199567379
, -3.37272359631325491
,
3.37930993039341754
, 1.97814699431758090
]
[ 2.50000000000000000
, -2.13934166115934765
, -4.08805856231715214
,
3.77306761197420482
, 1.94871690115780605
]]

procedurelist output:
> deqn4 := { diff(y(t),t$3) - 2*diff(y(t),t$2) + 2*y(t) };
d3

d2

y
(
t
)

2
2 y( t ) 2 y( t ) }

dt3

dt

deqn4:= {

> init4 := { y(0)=1, D(y)(0)=1, (D@@2)(y)(0)=1 };


( 2)

init4:= { y( 0 )1, D( y )( 0 )1, ( D )( y )( 0 )1 }

> dsol4 := dsolve(deqn4 union init4, numeric, method=rkf45,


relerr=Float(1,-8), abserr=Float(1,-8),
maxfun=0, output=procedurelist);
dsol4:= proc(x_rkf45) ... end proc

34

> dsol4(0.05);

d
, y( t )1.04995673867843053
,
t0.05, y( t )1.05124946305338263
dt

d2

2 y( t )0.997371821503983624

dt

> dsol4(-0.45);

d
, y( t )0.571757535785405224
,
t-0.45, y( t )0.648630782805870165
dt

d2

2 y( t )0.870897136753005841

dt

Piecewise output for complex-valued problem:


> deqn5 := { diff(y(t),t) = I*y(t) };
d
deqn5:= { y( t )y( t ) I }
dt

> init5 := { y(0)=1 };


init5:= { y( 0 )1 }

> dsol5 := dsolve(deqn5 union init5, numeric, method=rkf45,


output=piecewise, complex=true,
range=0..Pi):
> length(dsol5);
7753

> eval(dsol5[2],t=0);
y( 0 )0.9999999997
0.4906666810-11 I

> eval(dsol5[2],t=evalf[15](Pi));
y( 3.14159265358979
)-1.000000643
0.238854434010-7 I

See Also

35

dsolve/Error_Control, dsolve[classical], dsolve[dverk78], dsolve[Events], dsolve[gear],


dsolve[lsode], dsolve[maxfun], dsolve[numeric,IVP], dsolve[numeric],
dsolve[rosenbrock], dsolve[Stiffness], dsolve[taylorseries], infolevel, plots[odeplot]

References
Enright, W.H.; Jackson, K.R.; Norsett, S.P.; and Thomsen, P.G. "Interpolants for
Runge-Kutta Formulas." ACM TOMS, Vol. 12. (1986): 193-218.
Fehlberg, E. "Klassische Runge-Kutta-Formeln vierter und niedrigerer Ordnung mit
Schrittweiten-Kontrolle und ihre Anwendung auf Waermeleitungsprobleme".
Computing. Vol. 6. (1970): 61-71.
Forsythe, G.E.; Malcolm, M.A.; and Moler, C.B. Computer Methods for
Mathematical Computations. New Jersey: Prentice Hall, 1977.
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.

36

Das könnte Ihnen auch gefallen