Upload
maria-lavinia-iordache
View
220
Download
0
Embed Size (px)
Citation preview
7/23/2019 Maple Dsolve Numeric
1/36
dsolve/numeric/DAE- find numerical solution of differential-algebraic initialvalue 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 dsolveto 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 dsolvecommand with the numericor type=numericoption and a real-valueddifferential-algebraic initial value problem (DA !"#) finds a numerical solution forthe DA !"#$ !f the optional equation method=numericmethodis provided (where
numericmethodis one of r%f&'dae, rosenbroc%dae, or mebdfi, dsolveuses that
method to obtain the numerical solution$
!n most cases dsolveis able to detect if the problem is a DA system, as opposed toan D system, namely the cases in which pure algebraic equations in the dependent
variables are present$ !f the input is a DA system containing no purely algebraic
equations, the method mustbe included to specify that the system is a DA system$
*onstrained mechanical systems often give rise to DA problems$ (+ee the pendulumeample below$)
The return value of dsolveand the following high level or common options arediscussed in dsolvenumeric.and dsolverror*ontrol.$
'output' = keyword or array
'range' = numeric..numeric
'abserr' = numeric or list
'relerr' = numeric
'stiff' = boolean
'known' = name or list of names
'optimize' = boolean
/
7/23/2019 Maple Dsolve Numeric
2/36
The eception is that for the DA solvers the absolute error tolerance can be specified
as a per-component list$ 0or epected behavior, the variables of the problem must also
be specified as a list, and the entries of 'aserr'must correspond /-/ to the variablesin the list, or to the variables in the system converted to first order using the order of
the variables in the list$ 0or more information, see the 1dsolvenumeric,!"#.help
page$ The default DA !"# method is a modifiedRunge-Kutta Fehlbergmethod, which
uses a base order &-' method, but has been modified to find solutions for DA
problems$ The default sti!!method is aRosenbrockmethod, which uses a base order
2-& method$ 0or a description of the modifications done to these methods inetending them to DA solution, see the 1daeetensionhelp page$ The other method
available for DA !"# is the dsolvemebdfi.method, which is short for 3odified
tended 4ac%ward-Differentiation 0ormula !mplicit method$
!n general, the DA !"# solvers are very similar to the standard differential !"#solvers, so this page is primarily concerned with outlining the differences between
them$
The DA solvers are currently restricted to finding solutions for real-valuedproblems$
0or use of any of the methods, the specified initial conditions must satisfy all hiddenconstraints of the system (that is, they must be a consistent set of initial conditions
with respect to the DA)$ !n the event that they do not, an error results, and
information is provided on the unsatisfied condition$
!n some cases, it may be necessary to use fsolveto compute consistent initialconditions for the problem$
!f the 1daeetensionmethods are in use, the differential option is set to true, and thesystem is sufficiently linear in the algebraic variables (i$e$, variables which have noderivatives appearing in the input system), it is possible to s%ip initial conditions for
those variables$ !f the initial conditions are s%ipped when they are required, an error
will be produced$
The following options are also available for some or all of the DA methods5'minstep' = numeric
'maxstep' = numeric
'initstep' = numeric
'startinit' = boolean
'events' = list
'event_pre' = keyword
'event_maxiter' = integer
'projection' = boolean
'differential' = boolean
6
7/23/2019 Maple Dsolve Numeric
3/36
'implicit' = boolean
'parameters' = list of names
'minstep', 'ma"step', and 'initstep'
These options are discussed in dsolverror*ontrol., and are only available for the
dsolvemebdfi.method$
'startinit'= oolean
This option controls the behavior of the numerical integration with respect to
consecutive calculations$ This option is described in dsolvenumeric,!"#.$
0or the default methods, r%f&'daeand rosenbroc%dae, when a 'range'has been
specified, the solution is recomputed only when the new value of the independentvariable 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 ma%ing
evaluation of the solution for an already computed interval quite inepensive (the
solution values are obtained by interpolation)$ The storage of the solution can also beenabled by using the storageargument$ The startinitparameter also forces these
methods to recompute the solution whenever a solution value is desired$
'events'= list
'event#pre'= keyword
'event#ma"iter'= integer
These options are available only for the r%f&'daeand rosenbroc%daemethods, and
are used to specify and control the behavior of events$ These are the same as forstandard !"# problems$ 0or a description, see the 1dsolvenumeric,!"#.and 1
dsolvevents.help pages$
'pro$ection', 'di!!erential', and 'implicit'
The 'pro$ection', 'di!!erential'and 'implicit'options are specific to the etensionmethods, so they are discussed there$
!n addition to the computation of solution values for the given input problem, theprocedure returns (that is, output7procedurelist, listprocedureor operator) provide
additional interactive features, including the ability to specify parameters$!nformation on these features is provided on the dsolvenumeric,interactive.page$
The eception is that the med!imethod cannot wor% with parametri8ed problems$
E"amples
As a first eample, we consider the problem of modeling the dynamics of a mass on astring of unit length in 6-D *artesian coordinates (the pendulum problem)$ 9e let rbethe position of the mass on the string, and vthe velocity5
:VectorCalculus[SetCoordinates](cartesian):
:VectorCalculus[BasisFormat](false):
: r := VectorCalculus[Vector]([x(t),y(t)]);
2
7/23/2019 Maple Dsolve Numeric
4/36
57r
( )t
( )yt
: v := VectorCalculus[diff](r,t);
57v
ddt
( )t
d
d
t( )yt
+ince the mass is on a string of fied length l, we have the constraint5
: con := VectorCalculus[ot!roduct](r,r)"l#$;
57con + ( )t 6 ( )yt 6 l6
ow we want to construct the DA system using the uler-
7/23/2019 Maple Dsolve Numeric
5/36
57Q ? @, , 6 ( )t ( )t m d
d
t6
( )t +( )t 6 ( )yt 6 l6 m g 6 ( )t ( )yt m d
d
t6
( )yt
: .x := isolate(select(-as,,diff(x(t),t,t))[0],diff(x(t),t,t));
57EQx =d
d
t6
( )t 6( )t ( )t
m
: .y := isolate(select(-as,,diff(y(t),t,t))[0],diff(y(t),t,t));
57EQy =d
d
t6
( )yt +m g 6 ( )t ( )yt
m
: .c := remove(-as,,diff)[0];
57EQc +( )t 6 ( )yt 6 l6
ow we have the equations of motion for the pendulum$ et, we need to determine
consistent initial conditions$ To do so, we must identify any hidden constraints of thesystem$ These are easy to find, as we have only one constraint$
: con := diff(.c,t);
57Dcon 6 ( )t d
d
t( )t 6 ( )yt
dd
t( )yt
: con := eval(diff(con,t),1.x,.y2);
57DDcon + +6 d
d
t( )t &
( )t 6 ( )tm
6 d
d
t( )yt 6
( )yt ( )+m g 6 ( )t ( )ytm
ur initial conditions must satisfy Ec, Dcon, and DDconat the initial point, leavingonly 6 degrees of freedom for the conditions$ +o for a pendulum starting at the minimum
value of y()* = +lhaving an initial hori8ontal velocity of D("*()* = v", we get5
: sys := 1y(3)="l,(x)(3)=vx2 union
eval(convert(1.c,con,con2,),t=3);
sys 6 ( ) ( )( )Dx 6 ( )y ( )( )Dy +( ) ( )y l, ,?57
+ +6 ( )( )Dx 6 &( )
6( )
m6 ( )( )Dy
66
( )y ( )+m g 6 ( ) ( )y m
=( )y l, ,
=( )( )Dx vx@
'
7/23/2019 Maple Dsolve Numeric
6/36
: ini := [solve(sys,1x(3),y(3),(x)(3),(y)(3),lam+da(3)2)][0];
57n ? @, , , ,=( ) /
6
m ( )+vx6 l gl6
=( ) =( )y l =( )( )Dx vx =( )( )Dy
+o we consider the above with a pendulum of unit length l = ,having unit mass m = ,
and an initial hori8ontal velocity of v" = ,/,), giving us the DA system and initial
conditions5
: dsys := eval(1.x,.y,.c2,1l=0,m=0,=456,vx=0&032);
57dsys ? @, , +( )t 6 ( )yt 6 / =d
d6
t6
( )t 6 ( )t ( )t =d
d6
t6
( )yt =$> 6 ( )t ( )yt
: dini := eval(ini,1l=0,m=0,=456,vx=0&032);
57dn ? @, , , ,=( ) &$=' =( ) =( )y -/ =( )( )Dx /
/=( )( )Dy
9e can then obtain the solution as5
: dsol0 := dsolve(dsys union dini, numeric);
57dsol! proc( ) $$$ end prox"rk#$%"dae
: dsol0(0&$);
=t $' =( )t &$>=B'62B&&6'>>B =( )t $2/=2=6'&B&'&B>, , ,
=d
d
t( )t $'C&'2/&&=CCC'>/=/ =( )yt -$===&>=>//>=2>CB/, ,
=d
d
t( )yt $/>2>6B2C=&C22&2
: dsol0(0);
=t /$ =( )t &$=&===&=&='C26'= =( )t $2C>=2&&B>2&, , ,
=d
d
t( )t -$====2CBB=6&>>>B2 =( )yt -$=======2&>B62/&2, ,
=d
d
t( )yt -$2C>B>&6'2==&=
C
7/23/2019 Maple Dsolve Numeric
7/36
+olution with rosenrock#dae5
: dsol$ := dsolve(dsys union dini, numeric,met-od=rosen+roc78dae);
57dsol& proc( ) $$$ end prox"rosenbrock"dae
: dsol$(0&$);
=t $' =( )t &$>=B'/=//>'>C>> =( )t $2/=2=62C&BC2C=2B, , ,
=d
d
t( )t $'C&C6C&C>C>=BB/ =( )yt -$===&>=>/2'&2222&2=, ,
=d
d
t( )yt $/>&>6B6>B/BC26
: dsol$(0);
=t /$ =( )t &$=&===C6B>/B6/ =( )t $2C=C>&C26C2/&=, , ,
=d
d
t( )t -$====2CBB=&'6/C2>& =( )yt -$=======2CC=/2/>/, ,
=d
d
t( )yt -$2C>=B=>CC>>'B
+olution with med!i5
: dsol9 := dsolve(dsys union dini, numeric, met-od=me+dfi);
57dsol' proc( ) $$$ end prox"mebd#
: dsol9(0&$);
=t $' =( )t &$>=B'6&'/=&2''= =( )t $2/=2>>&2C=&>''/, , ,
=d
d
t
( )t $'C&>B/62&666'B' =( )yt -$===&>=>6'/>='=/6=, ,
=d
d
t( )yt $/>CB&'&C2C=/2
: dsol9(0);
B
7/23/2019 Maple Dsolve Numeric
8/36
=t /$ =( )t &$=&=B=&&B6&&6==2' =( )t $2C/=B2/6/=&'&=>, , ,
=d
d
t( )t -$====6'2=/=&BC&BB' =( )yt -$=======2&6C/>B=', ,
=ddt
( )yt -$2'=>>/C//'=2/B=
ow consider a similar problem as above, but in addition add a second mass supported
from the first by another string, this one of length /6 (the double pendulum)$ The system
can be obtained and solved as5
: dsysd := 1
diff(x0(t),t,t) $'lam+da0(t)'x0(t)$'lam+da$(t)'(x0(t)"x$(t)),
diff(y0(t),t,t)456$'lam+da0(t)'y0(t)$'lam+da$(t)'(y0(t)"y$(t)),
diff(x$(t),t,t)"$'lam+da$(t)'(x0(t)"x$(t)),
diff(y$(t),t,t)456"$'lam+da$(t)'(y0(t)"y$(t)),
x0(t)#$y0(t)#$"0,
(x0(t)"x$(t))#$(y0(t)"y$(t))#$"0&
2;
dsysd
d
d
t6
( )6t 6 ( )2t ( )( )/t ( )6t + ( )( )/t ( )6t 6 ( )( )y/t ( )y6t 6/
&, ,?57
+ ( )/t 6 ( )y/t 6 / + +d
d6
t6
( )/t 6 ( )1t ( )/t 6 ( )2t ( )( )/t ( )6t, ,
+
d
d6
t6( )y6t =$> 6 ( )
2t ( )
( )y/t ( )y6t ,
+ + +d
d6
t6( )y/t =$> 6 ( )1t ( )y/t 6 ( )2t ( )( )y/t ( )y6t @
: ics := 1x0(3)=3,(x0)(3)="9,y0(3)="0,(y0)(3)=3,
x$(3)=3,(x$)(3)=,y$(3)="9&$,(y$)(3)=32;
>
7/23/2019 Maple Dsolve Numeric
9/36
cs =( )/ =( )6 =( )y/ -/ =( )y6 -2
6=( )( )Dx! -2 =( )( )Dx& & =( )( )Dy! , , , , , , ,?57
=( )( )Dy& @
: dsold := dsolve(dsysd union ics,numeric);
57dsold proc( ) $$$ end prox"rk#$%"dae
The traEectory of the second mass can be plotted via5
:
7/23/2019 Maple Dsolve Numeric
10/36
rosenbroc%,bvp, r%f&'dae, rosenbroc%dae, dver%B>, lsode, gear, taylorseries,
mebdfi, or classical), dsolveuses that method to obtain the numerical solution$
4oth initial and boundary value problems can be numerically solved, as well as initialdifferential algebraic problems$ 0or a system input, the type of problem is
automatically detected, but for some DA problems it may be necessary to specify
the method$4y default, a procedure is returned that can be used to obtain solution values if giventhe value of the independent variable$
The default for initial value problems (!"#) is a Funge-Gutta 0ehlberg method thatproduces a fifth order accurate solution (0or more information, see r%f&'ornumeric,!"#)$ 0or boundary value problems (4"#), a finite difference technique with
Fichardson etrapolation is used (0or more information, see numeric,4"#)$ 0or
differential-algebraic !"# problems (DA), a modification of the r%f&' method is
used (0or more information, see daeetension)$
All .&Pmethods can be used for comple-valued !"#s with a real-valued
independent variable (though for the default stiff and nonstiff !"# methods, it may benecessary to specify that the problem is comple via the comple"option)$ one of
the &Por DAEmethods can currently be used for comple-valued problems,requiring the system be converted to a real system before calling dsolve$
The .&Pand DAEmethods have additional capabilities for the returned solutionprocedure$ +pecifically, it is possible to query the last computed solution value (useful
for problems with singularities), query the initial data, and change the initial data forsome solution procedures (DAEmethods support a subset of this)$ 0or more
information, see numeric,!"#and numeric,DA$
9hen the set of dependent variables is specified as a list, then this specifies the orderof the dependent variables as they appear in the output$ The order is otherwisealphabetical in the dependent variable name$
0ptions
The high-level options, most common to !"#s, 4"#s, and DAs 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
/
7/23/2019 Maple Dsolve Numeric
11/36
'output'= keyword or array
Geyword that can ta%e the values procedurelist, listprocedure, operator, or
piecewise, or an arrayor Arraythat gives the values of the independent variable at
which solution values are desired$The default %eyword is procedurelist, which gives the output from dsolveas aprocedure$ This procedure accepts the value of the independent variable as an
argument, and it returns a list of the solution values of the form variale=value,
where the left-hand sides are the names of the independent variable, the dependentvariable(s) and their derivatives (for higher order equations), and the right-hand sides
are the corresponding computed solution values$
The listprocedure%eyword gives the output as a list of equations of the formvariale=procedure, where the left-hand sides are the names of the independentvariable, 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, foreample, fsolve$
The operator%eyword 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 eample,1result2(,*)$
The piecewise%eyword is available only for non-stiff and stiff default !"# and DA
methods (r%f&', rosenbroc%, r%f&'dae, and rosenbroc%dae) and the taylorseries
method$ !t provides output as a list of equations of the form variale = pw!unc,where the left-hand sides are the names of the independent variable, the dependent
variable(s) and derivatives, and the right-hand sides arepiecewisepolynomial
functions describing the corresponding solution components$ Thesepiecewisefunctions are obtained from the method interpolants for each step of the computation$
!n addition, the form of the piecewise polynomials can be specified using an inde on
the piecewise output request$ +pecification of output=piecewise1horner2providesoutput in terms of horner-form polynomials (the default for taylorseries), while
specification of output=piecewise1polynomial2provides output in terms of standard
polynomial form (the default for all other methods)$ Hse of this output form requiresthat the 'range'argument be used to specify to dsolve/numericthe desired range of
the piecewise function$
!f an arrayis used, it must be a vector of floats that defines the values of the
independent variable at which solution values are desired$ 9hen this option is given,a 6 / matri"is returned (instead of a solution procedure)$ The 1,3 ,2entry is an
array containing the name of the independent variable and the names of the dependent
variable(s) and derivatives$ The 1-3 ,2entry is a matri$ The first column of thismatri is a copy of the outputvector, that is, the values of the independent variable$
//
7/23/2019 Maple Dsolve Numeric
12/36
The other columns are values of the dependent variable(s) and derivatives
corresponding to the vector of names in 1,3 ,2$ Fow iof this matri is the vector
containing both the value of the independent variable and the values of the dependentvariables evaluated at element iof the outputarray$
4ote5!f an Arrayis used, then the output is the same as for an arrayecept the
newer Arrayand 6atri"datatypes are used in the output$ 0or a large number ofoutput points andor solution components, the output data may not be directly visible
because there is a default si8e at which the representation of an Arrayor 6atri"is
displayed instead of an inline display of the data itself$ 0or more information, see
interface(rtablesi8e)$
'sti!!'= oolean
4oolean that is used only for !"# and DA$ +etting sti!!=true(thoutselecting a
method specifies that the default stiff methods (rosenbroc%or rosenbroc%dae) must
be used instead of the default non-stiff methods (r%f&'or r%f&'dae)$ 9hen themethod is also specified, a consistency chec% is performed to verify that the method
matches with the 'sti!!'value$ 0or more information on the phenomena of stiffness,
see dsolve+tiffness.$
'events'= list
'event#pre'= keyword
'event#ma"iter'= integer
Arguments that are available only for real-valued !"#s or DAs using the non-stiff
and stiff default methods, r%f&', rosenbroc%, r%f&'dae, or rosenbroc%dae, and areused to specify and control the behavior of events$ These options are discussed in
detail in dsolvevents.$
'range'= numeric777numeric
"alues that specify the range of the independent variable over which solution valuesare desired$
0or !"#s and DAs this option is used only by the non-stiff and stiff default methods
(r%f&', rosenbroc%, r%f&'dae, rosenbroc%dae) and the taylorseriesmethod$ !t hastwo purposes for procedure-type output$ !f '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$
4otes5
- 9hen 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 re!ineoption of odeplot(rk!89:androsenrock:only) allows better plotting of the details of the solution$ !f 'range'is
not used, then the call to dsolvereturns a procedure that does notstore the computed
solution, but rather computes the solution whenever a point is requested$
- 0or 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$
/6
7/23/2019 Maple Dsolve Numeric
13/36
0or the 4"#method, this option is only needed when the 4"# method is to be used
to solve an !"# with a global error bound, as for 4"# the information can be inferred
from the boundary conditions in deqns$ 0or more information, see numeric,4"#$
'aserr'= numeric or list
umeric value that gives a limit on the absolute error tolerance for a successful step
in the !"# and DA cases, and a measure of the maimum error between thecomputed solution and the eact solution in the 4"# case (in all but eceptionalsystems)$ !t is supported by all methods ecept the classicalmethods (as all classical
methods are implemented with a fied step si8e and no error control)$ The list form of
abserr is available for the rk!89:, rosenrock:, and med!i!"# and DA methods,and allows specification of absolute error tolerances that are different for each
dependent variable, or for each solution component$ 3ore detail on this can be found
in the dsolvenumeric,!"#.page and the dsolverror*ontrol.page$
'relerr'= numeric
umeric value that gives a limit on the relative error tolerance for a successful step
for an !"# or DA$ This option wor%s in conEunction with 'aserr'$ !t is supported by
all methods ecept classical, taylorseries, andbvp$
Defaults for 'aserr'and 'relerr'are specific to each method, but it should be notedthat the default error tolerance for the default non-stiff r%f&'method is now fied
(rather than controlled by the value of Digits)$
0or a detailed discussion about error control, see dsolverror*ontrol.$
'known'= name or list o! names
#rovides a list of functions that should be considered as kno(nwhen eamining the
system$ This allows for specification of a system containing user-defined functions$
ach user defined function must always return numerical values when given numericinput, and must return unevaluated when given name input$ 0or an illustration of the
use of this option, see the E"amplessection below$
4ote5!n most cases, use of a system with a user-defined function prevents the use of
evalhfwithin dsolve, so obtaining a solution using this facility will run noticeablyslower than specification of the system in terms of %nown functions (when it is
possible to epress the system in this way)$
All methods ecept taylorseries, rosenbroc%, and rosenbroc%daesupport this option
directly, but for these two methods additional information is required$ The %eyproblem is that these two methods require information on the derivatives of the input
D system, which is not directly available when functions are procedure defined$ !t
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 ;di!!/;rules$ The rosenrockmethodrequires only a single derivative, but the taylorseriesmethod requires derivatives to
arbitrary order, so with taylorseriesit 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 di!!rule defined$ The
rosenrock#daemethod may require more than a single derivative, as the DApreprocessing may need to differentiate the input system$
/2
7/23/2019 Maple Dsolve Numeric
14/36
0or taylorseries, rosenbroc%, and rosenbroc%daeuse of multiple argument functions,
or functions that also depend on the dependent variables or derivatives of the problem
are tric%y, and have some limitations$ The details of this are deferred to the respectivehelp pages$
'optimi
7/23/2019 Maple Dsolve Numeric
15/36
: dsn0(0);
., ,=t /$ =( ) t A$'&A2A622/BB'>'6=C6 =( )y t -A$>&/&B//A//'BC/=C=
: [t = 05, x(t) = 35393$939$?9@0, y(t) =
"3560?009@3$49406]; ., ,=t /$ =( ) t A$'&A2A62A&2&6B'2C/& =( )y t -A$>&/&B//2CA6'=2=/&
: dsn$ := dsolve(dsys,numeric,[y(t),x(t)]): > s&/&B//A//'BC/=C=& =( ) t A$'&A2A622/BB'>'6=C
: [t = 05, y(t) = "3560?009@3$49406, x(t) =35393$939$?9@0];
., ,=t /$ =( )y t -A$>&/&B//2CA6'=2=/&> =( ) t A$'&A2A62A&2&6B'2C/
+traightforward second order !"#5
: deA0 := (t0)#$'diff(y(t),t,t) (t0)'diff(y(t),t)
((t0)#$"35$)'y(t) = 3;
57de)! =+ +( )+t / 6
d
d6
t6
( )yt ( )+t /
d
d
t
( )yt ( )( )+t / 6 $6' ( )yt
: ic0 := y(3) = 35@?094@?3?006393,
(y)(3) = 3534330??@:
: dsol0 := dsolve(1deA0,ic02, numeric, rane=3550);
57dsol! proc( ) $$$ end prox"rk#$%
: dsol0(3);
, ,=t $ =( )yt $CB/2=CBB/&/>2 =d
d
t( )yt $='&'/&&&B&B&
: dsol0(35);
, ,=t $' =( )yt $C&=>2>/2B2C>>>=>C =d
d
t( )yt -$/B'6='C6>/6>/2=
/'
7/23/2019 Maple Dsolve Numeric
16/36
: dsol0(0);
, ,=t /$ =( )yt $'/2/C=/&>/6B' =d
d
t( )yt -$2C22=>626&&2B6C
+ame second order !"# with operator output5
: dsol0+ := dsolve(1deA0,ic02, numeric, out2>A/2B2C>>>=>C =( )( )D y A$' -A$/BA'6='C6>/6>/2=6
: dsol0+(0);
., ,=t /$ =( )y / A$'/2A/CA=A/A&>/6B'A =( )( )D y / -A$2C2A2=>6A26&&2B/'
0irst order !"#5
: dsol$ := dsolve(1diff(y(x),x) = y(x)'cos(x), y(3) = 02,
numeric, out2&&C//A/AA$======B>'>&=AC6=
0irst order !"# with piecewise output5
: dsol$< := dsolve(1diff(y(x),x) = y(x)'cos(x), y(3) = 02,
numeric, out
7/23/2019 Maple Dsolve Numeric
17/36
dsol&* =x x ( )yx ,unde#ned '>'=6C26/$6BB'/6CC6/C/>x $&==&C=&&6=2=B( )x $6BBC6/62/'B/6>6+ +
$/&'2&''2&=2&( )x $6BBC6/62/'B/6>&2
$/22>2'6=''6'/6C( )x $6BBC6/62/'B/6>&& x $'''6&6&C2/&6'C>',
$=>=//''6/22/6/$/&B/=>'6/6/C&x $&>/=///BBB/B'( )x $/&=/26C6>&B=>C+ +
$=&=/>B&=BC&22( )x $/&=/26C6>&B=>C2
$/B62/26C'C'C&2( )x $/&=/26C6>&B=>C& x $6&6'66B=2>/B/&=6',
$=&>2=B&CC/&B>>/$2/'=B&66BC6=/x $2>B&6>C>2CB6C>2( )x $2&'B2>>62'B26+ +
$6&&'B/='6C=/B/=( )x $2&'B2>>62'B2
$66B/2B6&B//C/=( )x $2&'B2>>62'B2& x $&2BC/6&=CCC'&6=CB2,
$>=B&6'6/C>/''26/$&2&B'C6==B>6C'x $/>26>>6/&/2&//'( )x $'&/2CB'22&B='B6+ +
$&26C2&B&C&/&6/B( )x $'&/2CB'22&B='B2
$66'>>C='>>66=>( )x $'&/2CB'22&B='B& x $C&'/66'B6=2B/&'/,
$>=>6B6==2C2&C/$&&>2=6&26&Cx $/226''=B6&>C&>>( )x $B&2C6>'&>B=/BC6+
$'=>B&'CC>&CB'CB( )x $B&2C6>'&>B=/BC2
$/''/=''2C=>/( )x $B&2C6>'&>B=/BC&
x $>&6/2&'//&C&C&/C>=,
$=>/B&&&26>==/$2&/22B>66B&Bx $&BB6&6/C=>'66( )x $=6/CB6''B2626/6+
$CB2'22>B&==>=/( )x $=6/CB6''B2626/2
$/&2C''B6CB==B>( )x $=6/CB6''B2626/& x /$,,unde#ned other(se.
+tiff nonlinear problem5
: dsys9 := diff(x(t),t) = x(t)#$ " t#@, x(3)="350;
57dsys' ,=d
d
t( )t ( )t 6 tC =( ) -$/
: dsol9 := dsolve([dsys9], ty
7/23/2019 Maple Dsolve Numeric
18/36
57dsol'
.,t ( )t
$ -$/
$6'-$=B'C=B&B'//CB'2
$'-$=C2&B26'26B22=6&
$B'-$///B&&B=//62==2B>
/$ -$66=6B=6C&2'=2>22
=B'' =ddx
( )yx $C26CBB>'C>&C&&C
: dsol($);
, ,=x 6$ =( )yx /$6/6= =d
d
x( )yx /$=B&//=6&2C'6&>
onlinear 4"#5
: dsys := 1diff(y(x),x,x) a+s(y(x)) = 3, (y)(3) = 0,
y(0) = "02;
57dsys% ? @, ,=+d
d6
x6
( )yx ( )yx =( )y / -/ =( )( )Dy /
: dsol := dsolve(dsys, numeric,out
7/23/2019 Maple Dsolve Numeric
19/36
57dsol%
, ,x ( )yx d
d
x( )yx
$ -/$&=C&>&6='>B'6&62/$&&
$6' -/$6/2/B'2=C>/''=/=$CB'2/>'&&/BB/&C&6
$' -/$C>&C>C''/C2C=$2=2C&B>C//62=>C&'
$B' -/$6B2/'6B/2/&=2'$/2'''B=&>=C=>2
/$ -$===============>=-$//2'2=>>62C/'6'>B
DA5
: dsys@:= 1
diff(x(t),t,t) = "$'lam+da(t)'x(t),
diff(y(t),t,t) = "$'lam+da(t)'y(t)"!i#$,
x(t)#$y(t)#$ = 0, x(3)=3, (x)(3)=0&03, y(3)="0, (y)(3)=32;
dsys+ =+( )t 6 ( )yt 6 / =d
d
t6( )t 6 ( )t ( )t =
d
d
t6( )yt 6 ( )t ( )yt 6 =( ) =( )y -/, , , , ,?57
=( )( )Dx /
/=( )( )Dy , @
: dsol@ := dsolve(dsys@, numeric);
57dsol+ proc( ) $$$ end prox"rk#$%"dae
: dsol@(0);
=t /$ =( )t &$=2=>66B2=>'BC =( )t $C22CB22>&2226CC6//-', , ,
=d
d
t( )t -$/C&=B'B2>/B =( )yt -$==========B>>B/, ,
=d
d
t( )yt -$C22CB2B'==/C=&2/
-C
Hse with !solve5
: dsys? := 1diff(y(x),x)=$'y(x), y(3)=02;
57dsys, ? @,=d
d
x( )yx 6 ( )yx =( )y /
/=
7/23/2019 Maple Dsolve Numeric
20/36
: iits := $3;
57Dgts 6A
: dsol? := dsolve(dsys?, numeric, met-od=ear, a+serr=0e"0@,
relerr=0e"0@, out
7/23/2019 Maple Dsolve Numeric
21/36
end /&=6=&B==C/C&/
: dsol6($);
.,=x 6$ =( )y x &$/=/CB==2///CA='=
A method that requires derivatives,
: dsolve(dsys6, numeric, met-od=rosen+roc7, 7non=f);
Error !in dsolve"numeric"ceckknown% use of 'rosenbrock'metod wit procedure defined function f re&uires a
differentiation rule ,diff"f,which failed because a differentiation rule is required$ 9e then clear the remember table
of diff and define this as5
: foret(diff);
: Ediff&fE := C-ain rule
6/
7/23/2019 Maple Dsolve Numeric
22/36
diff(ars[0],ars[$])'ex
7/23/2019 Maple Dsolve Numeric
23/36
4oyce, 9$$, and Di#rima, F$*$ Elementary Di!!erential Equations and oundary
&alue Prolems$ ew Nor%5 Oohn 9iley P +ons, /==B$
*ash, O$F$ MThe !ntegration of +tiff !"# in D Hsing 3odified tended 4D0$MComputers and 6athematics with Applications$ "ol$ ?$ (/=>2)5 C&'-C'B$
Qear, *$9$ 4umerical .nitial &alue Prolems in 0rdinary Di!!erential Equations$
#rentice-Lall, /=B/$
Lindmarsh, Alan *$; +tepleman, F$+$; et al, eds$ 0depack3 a Systemi2$
Lubbard O$L$, and 9est, 4$L$ Di!!erential Equations5 A Dynamical Systems
Approach$ ew Nor%5 +pringer, /==$ #art .$ 0ne Dimensional Equations$
Lull, T$$; nright, 9$L$; 0ellen, 4$3$; and +edgwic%, A$$ M*omparing umerical3ethods for rdinary Differential quations$M S.A6 @7 4umer7 Anal7"ol$ ?$ (/=B6)5
C2-C2B$
+hampine,
7/23/2019 Maple Dsolve Numeric
24/36
Description
The dsolvecommand with the options numericand method=classicalormethod=classical1choice2finds a numerical solution by using one of the classcalnumerical methods as described in the following$
These methods use a fied step si8e, provide no error estimation or correction, and are
provided primarily for educational purposes$ !f practical numerical solution of D
initial value problems (!"#) is required, it is suggested that any of the other methodsmentioned in dsolvenumeric,!"#.help page be used instead$
A number of classical methods are available through use of the choiceoption in themethod=classical1choice2selection$ The default is !oreuler, the forward uler
method$
The available choices of the classicalmethod are described for the problem y'=!(t3y*,where 1i2is the estimated value of the solution at the time t1i2, his the fied step
si8e t1i2+t1i+,2, and for each formula the value of the solution 1nB,2at time t1nB,2is
being computed$
!oreuleris the#or(ard Eulermethod specified by the equation5 /n0+ = /n 0 1f!tn /n%
heun!ormis the.eunformula (also %nown as the improved uler method)$ !t usesthe#or(ard Eulermethod to predict the solution, and then applies the tra*e/od rule
as a corrector$ !t is specified by the pair of equations5
/p = /n 0 1f!tn /n%
/n0+ = /n 0 !"(%1!f!tn/n% 0 f!tn0+/p%%
impolyis the m*roved *olygonmethod (also %nown as the modified uler method),
as specified by the equation5 /n0+ = /n 0 1!f!tn0"( /n0!"(%1f!tn/n%%%
rk-is thesecond-order classcal Runge-Kuttamethod, as specified by5 k+ = f!tn /n%
k( = f!tn0 /n01k+%
/n0+ = /n 0 !"(%1!k+0k(%
4ote5This is the same as the.eunformula$
rk>is the thrd-order classcal Runge-Kuttamethod, as specified by5 k+ = f!tn /n%
k( = f!tn0!"(% /n0!"(%1k+%
k2 = f!tn0 /n01!-k+0(1k(%%
/n0+ = /n 0 !"3%1!k+041k(0k2%
6&
7/23/2019 Maple Dsolve Numeric
25/36
rk8is the#ourth-order classcal Runge-Kuttamethod, as specified by5 k+ = f!tn /n%
k( = f!tn0"( /n0!"(%1k+%
k2 = f!tn0"( /n0!"(%1k(%
k4 = f!tn0 /n01k2%
/n0+ = /n 0 !"3%1!k+0(1k(0(1k20k4%
This is not to be confused with method=rk!89, which uses aFehlberg #ourth-##thorder Runge-Kutta method$
adamashis the0dams-1ash#orthmethod (a predictor method), as specified by5 /n0+ = /n 0 !"(4% 1 !551f!tn/n% - 561f!tn-+/n-+%
0 271f!tn-(/n-(% - 61f!tn-2/n-2%%
amoultonis the0dams-1ash#orth-Moultonmethod (a predictor-corrector method),as specified by5
/n0+ = /n 0 !"(4% 1 !61f!tn0+/n0+% 0 +61f!tn/n%
- 51f!tn-+/n-+% 0 f!tn-(/n-(%%
where !(t1nB,231nB,2*is found by first applying the Adams-4ashforth method (the
predictor), then using the above Adams-4ashforth-3oulton method (the corrector)$
The following options are available for the classicalmethod5 '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
6'
7/23/2019 Maple Dsolve Numeric
26/36
'corrections' = integer
'output'
+pecifies the desired output from dsolve, and the knownoption specifies user-
defined %nown functions$ 0or more information, see dsolvenumeric.$
'ma"!un'
+pecifies a maimum on the number of evaluations of the right-hand side of the firstorder D system$ This option can be disabled by specifying ma"!un=)$ The default
value for classicalmethods is 9))))$ 0or more information, see dsolvemafun.$
'numer', 'procedure', 'start', 'initial', and 'procvars'
These options are used to specify the !"# using procedures$ 0or more information,
see dsolvenumeric,!"#.$
'startinit','implicit', and 'optimi
7/23/2019 Maple Dsolve Numeric
27/36
: init0 := y(3) = 0, (y)(3) = $, (GG$)(y)(3) = "0,
x(3) = , (x)(3) = 59;
57nt! , , , ,=( )y / =( )( )Dy 6 =( )( )( )D( )6
y -/ =( ) & =( )( )Dx &$2
: ans0 := dsolve(1dsys0,init02, numeric,
met-od=classical[a+moulton], corrections=$);
57ans! proc( ) $$$ end prox"classcal
: ans0(053);
=t /$ =( )t /2$/6&C=2B=6B/'C>2 =d
d
t( )t />$B>BC=/'2'/&6/', , ,
=( )yt 2$BC6>2&/262C/6C =ddt
( )yt '$2/BC2=BC>6/C2C6 =dd
6
t6
( )yt /$6'&C>2C62'=C2, ,
: deA$ := diff(y(x), x$) = y(x);
57de)& =d
d6
x6
( )yx ( )yx
: init$ := y(3) = 0, (y)(3) = 0;
57nt& ,=( )y A / =( )( )D y A /
: iits := $3:
ans$ := dsolve(1deA$, init$2, numeric,
met-od=classical[-eunform],
out
7/23/2019 Maple Dsolve Numeric
28/36
57ans&
, ,x ( )yx d
d
x( )yx
$/ /$/'/C'&6/2/B/'/$/'/C'&6/2/B/
$/ /$/'/B>==CC==&/'>>/$/'/B>==CC==&/'>>
/$ 6$B/>6>/2B'B'/BC>2==6$B/>6>/2B'B'/BC>2=
: iits := 03:
deA9 := 1 diff(y(t),t) " diff(y(t),t9) = y(t)'t#$ 2;
57de)' ? @=d
d&
t&
( )yt
dd
2
t2
( )yt ( )yt t6
: init9 := 1 y(3) = 95@, (y)(3) = 0$, (GG$)(y)(3) = ",
(GG9)(y)(3) = @5 2;
57nt' ? @, , ,=( )y 2$'C =( )( )Dy /6 =( )( )( )D( )6
y -& =( )( )( )D( )2
y C$'&&
: ans9 := dsolve(deA9 union init9, numeric,
met-od=classical[r79], outB'A&B=6&>AC=&=
See Also
dsolvedver%B>., dsolvegear., dsolvelsode., dsolvemafun., dsolvenumeric.,
dsolvenumeric,!"#.,plotsodeplot., dsolver%f&'., dsolverosenbroc%.,
dsolvetaylorseries.
e!erences
4oyce, 9$$, and Di#rima, F$*$ Elementary Di!!erential Equations and oundary&alue Prolems$ 'th ed$ ew Nor%5 9iley, /==6$
*onte, +$D$, and *$ de 4oor$ Elementary 4umerical Analysis3 An Algorithmic
Approach$ 3cQraw-Lill, /=>$
6>
7/23/2019 Maple Dsolve Numeric
29/36
0o, B$
7/23/2019 Maple Dsolve Numeric
30/36
This method can be used in combination with the re!ineoption of odeplotto produce
an adaptive plot (that is, odeplotuses the precomputed points to produce the plot
when re!ineis specified$)
!t 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 ta%en 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 theinterpolation=!alseoption 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 recommendedbecause the solution values are obtained from an interpolation of the ' closest points,
and does not necessarily provide an interpolant with order & error$
9ithout the rangeoption9hen used without the rangeoption, the !"# solution values are not stored, butrather computed when requested$
4ecause not all solution values are stored, computation must restart at the initialvalues 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 tocollect solution values moving away from the initial value$
0ptions
The following options are available for the rk!89method$'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
2
7/23/2019 Maple Dsolve Numeric
31/36
'compile' = boolean or 'auto'
'range' = numeric..numeric
'events' = list
'event_pre' = keyword
'event_maxiter' = integer
'event_iterate' = keyword
'event_initial' = boolean
'complex' = boolean
output
+pecifies the desired output from dsolve$ The %eywords procedurelist,
listprocedure, or operatorprovide procedure-type output, the %eyword piecewiseprovides output in the form ofpiecewisefunctions over a specified range of
independent variable values, and a /-D array or Array provide output at fied values
of the independent variable$ 0or more information, see dsolvenumeric.$
known
+pecifies user-defined %nown functions$ 0or more information, see dsolvenumeric.$
aserr, relerr, and initstep
+pecify the desired accuracy of the solution, and the starting step si8e for the method$
0or more information, see dsolverror*ontrol.$ The default values for rk!89areaserr = 7,e+and relerr = 7,e+9$ The value for initstep, if not specified, is
determined by the method, ta%ing into account the local behavior of the D system$interr
4y default this is set to true, and controls whether the solution interpolant error(including the interpolant on inde-/ variables for DA problems) is integrated into
the error control$ 9hen set to !alse, 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$ 9hen set to true, the step si8e isreduced to minimi8e error in these regions, but for problems where there is a Eump
discontinuity in the variables, the integration may fail with an error indicating that a
singularity is present$ !n the latter case where an error is thrown, it may beadvantageous to model the discontinuities using events (see dsolvevents.)$
ma"!un
+pecifies a maimum on the number of evaluations of the right-hand side of the first
order D system$ This option is disabled by specifying ma"!un = )$ The defaultvalue for rk!89is >))))$
numer, procedure, start, initial, and procvars
These options are used to specify the !"# using procedures$ 0or more information,
see dsolvenumeric,!"#.$
2/
7/23/2019 Maple Dsolve Numeric
32/36
startinit, implicit, and optimior gearmethodsbe used instead$
Fesults can be plotted by using the function odeplotin the plotspac%age$
E"amples
+olution with a range - solution over ) 77 ,is stored5
: dsys0 := 1diff(x(t),t)=y(t), diff(y(t),t)=x(t)y(t),
x(3)=$, y(3)=02;
26
7/23/2019 Maple Dsolve Numeric
33/36
57dsys! ? @, , ,=d
d
t( )t ( )yt =
d
d
t( )yt +( )t ( )yt =( ) 6 =( )y /
: dsol0 := dsolve(dsys0, numeric, out6C>>=6C&===&/'B
+olution without a range - each point is computed when requested5
: dsol$ := dsolve(dsys0, numeric, met-od=r7f,
out
7/23/2019 Maple Dsolve Numeric
34/36
: dsol9 := dsolve(dsys9 union init9, numeric, met-od=r7f,
out$=C2&/6//=2C'C&66>-$/>&>C&&>/6/BB>/ , , ,
$C2//6>2>BB6/'''''/$/&>6/>&'6B&>B&/B=, .
/$/=$BCC=/&BB=62/C/&&-$C'&2'=>'/>=266C= , , ,
/$6C==C'>/=B2&&66/2/$&6/6B&C66>/C2>BB6, .
/$'$2>BB&>&6>62BC&=&2&-/$6>6B&22C'B/&62C= , , ,
/$>>>&22>/CC'B'C///$CB&'6BC&>=B6'B, .
6$6==============>6-/$2=&'BCC/=='CB2B=-2$2B6B62'=C2/26'&= , , ,
2$2B=2==22=2&/B'&/$=B>/&C==&2/B'>=, .
6$'-6$/2=2&/CC//'=2&BC'-&$>>'>'C62/B/'6/ , , ,
2$BB2CBC//=B&6&>6/$=&>B/C=//'B>C', ..
procedurelistoutput5
: deAn := 1 diff(y(t),t9) " $'diff(y(t),t$) $'y(t) 2;
57de)n$ ? @ +d
d2
t2( )yt 6
d
d6
t6( )yt 6 ( )yt
: init := 1 y(3)=0, (y)(3)=0, (GG$)(y)(3)=0 2;
57nt$ ? @, ,=( )y / =( )( )Dy / =( )( )( )D( )6
y /
: dsol := dsolve(deAn union init, numeric, met-od=r7f,
relerr=Float(0,"6), a+serr=Float(0,"6),
maxfun=3, out
7/23/2019 Maple Dsolve Numeric
35/36
: dsol(353);
=t $' =( )yt /$'/6&=&C2'22>6C2 =d
d
t( )yt /$&=='CB2>CB>&2, , ,
=dd
6
t6 ( )yt $==B2B/>6/'2=>2C6&
: dsol("35);
=t -$&' =( )yt $C&>C2B>6>'>B/C' =d
d
t( )yt $'B/B'B'2'B>'&'6, , ,
=d
d6
t6
( )yt $>B>=B/2CB'2'>&/
#iecewise output for comple-valued problem5: deAn := 1 diff(y(t),t) = D'y(t) 2;
57de)n% ? @=d
d
t( )yt ( )yt 2
: init := 1 y(3)=0 2;
57nt% ? @=( )y A /
: dsol := dsolve(deAn union init, numeric, met-od=r7f,
out=B= +-/$C&2 $62>>'&&2&/- 2
See Also
2'
7/23/2019 Maple Dsolve Numeric
36/36
dsolverror*ontrol, dsolveclassical., dsolvedver%B>., dsolvevents., dsolvegear.,
dsolvelsode., dsolvemafun., dsolvenumeric,!"#., dsolvenumeric.,
dsolverosenbroc%., dsolve+tiffness., dsolvetaylorseries., infolevel,plotsodeplot.
e!erences
nright, 9$L$; Oac%son, G$F$; orsett, +$#$; and Thomsen, #$Q$ M!nterpolants forFunge-Gutta 0ormulas$M AC6 %06S, "ol$ ,-$ (/=>C)5 /=2-6/>$
0ehlberg, $ MGlassische Funge-Gutta-0ormeln vierter und niedrigerer rdnung mit
+chrittweiten-Gontrolle und ihre Anwendung auf 9aermeleitungsproblemeM$
Computing$ "ol$ $ (/=B)5 C/-B/$
0orsythe, Q$$; 3alcolm, 3$A$; and 3oler, *$4$ Computer 6ethods !or
6athematical Computations$ ew Oersey5 #rentice Lall, /=BB$
+hampine,