dsolve/numeric/DAE
find numerical solution of differential-algebraic initial value problems
Calling Sequence
Parameters
Description
Examples
dsolve(daesys, numeric, vars, options)
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
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, ck45_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'
'stiff'
boolean
'known'
name or list of names
'optimize'
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'
'maxstep'
'initstep'
'startinit'
'events'
list
'event_pre'
keyword
'event_maxiter'
integer
'projection'
'differential'
'implicit'
'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 methods, rkf45_dae, ck45_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, ck45_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.
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:
VectorCalculusSetCoordinates⁡cartesian:
VectorCalculusBasisFormat⁡false:
r≔VectorCalculusVector⁡x⁡t,y⁡t
r≔x⁡ty⁡t
v≔VectorCalculusdiff⁡r,t
v≔ⅆⅆtx⁡tⅆⅆty⁡t
Since the mass is on a string of fixed length l, we have the constraint:
con≔VectorCalculusDotProduct⁡r,r−l2
con≔x⁡t2+y⁡t2−l2
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≔m2⁢VectorCalculusDotProduct⁡v,v
T≔m⁢ⅆⅆtx⁡t2+ⅆⅆty⁡t22
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
L≔m⁢ⅆⅆtx⁡t2+ⅆⅆty⁡t22−m⁢g⁢y⁡t
ML≔L−λ⁡t⁢con
ML≔m⁢ⅆⅆtx⁡t2+ⅆⅆty⁡t22−m⁢g⁢y⁡t−λ⁡t⁢x⁡t2+y⁡t2−l2
We can then construct the Euler-Lagrange formulation via:
Q≔remove⁡has,VariationalCalculus:-EulerLagrange⁡ML,t,x⁡t,y⁡t,λ⁡t,K
Q≔−2⁢x⁡t⁢λ⁡t−m⁢ⅆ2ⅆt2x⁡t,l2−x⁡t2−y⁡t2,−m⁢g−2⁢y⁡t⁢λ⁡t−m⁢ⅆ2ⅆt2y⁡t
EQx≔isolate⁡select⁡has,Q,diff⁡x⁡t,t,t1,diff⁡x⁡t,t,t
EQx≔ⅆ2ⅆt2x⁡t=−2⁢x⁡t⁢λ⁡tm
EQy≔isolate⁡select⁡has,Q,diff⁡y⁡t,t,t1,diff⁡y⁡t,t,t
EQy≔ⅆ2ⅆt2y⁡t=−m⁢g+2⁢y⁡t⁢λ⁡tm
EQc≔remove⁡has,Q,diff1
EQc≔l2−x⁡t2−y⁡t2
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
Dcon≔−2⁢x⁡t⁢ⅆⅆtx⁡t−2⁢y⁡t⁢ⅆⅆty⁡t
DDcon≔eval⁡diff⁡Dcon,t,EQx,EQy
DDcon≔−2⁢ⅆⅆtx⁡t2+4⁢x⁡t2⁢λ⁡tm−2⁢ⅆⅆty⁡t2+2⁢y⁡t⁢m⁢g+2⁢y⁡t⁢λ⁡tm
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=vxunioneval⁡convert⁡DDcon,Dcon,EQc,D,t=0
sys≔−2⁢x⁡0⁢D⁡x⁡0−2⁢y⁡0⁢D⁡y⁡0,l2−x⁡02−y⁡02,−2⁢D⁡x⁡02+4⁢x⁡02⁢λ⁡0m−2⁢D⁡y⁡02+2⁢y⁡0⁢m⁢g+2⁢y⁡0⁢λ⁡0m,y⁡0=−l,D⁡x⁡0=vx
ini≔solve⁡sys,λ⁡0,x⁡0,y⁡0,D⁡x⁡0,D⁡y⁡01
ini≔λ⁡0=m⁢g⁢l+vx22⁢l2,x⁡0=0,y⁡0=−l,D⁡x⁡0=vx,D⁡y⁡0=0
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=110, giving us the DAE system and initial conditions:
dsys≔eval⁡EQc,EQx,EQy,g=9.8,l=1,m=1,vx=110
dsys≔1−x⁡t2−y⁡t2,ⅆ2ⅆt2x⁡t=−2⁢x⁡t⁢λ⁡t,ⅆ2ⅆt2y⁡t=−9.8−2⁢y⁡t⁢λ⁡t
dini≔eval⁡ini,g=9.8,l=1,m=1,vx=110
dini≔λ⁡0=4.905000000,x⁡0=0,y⁡0=−1,D⁡x⁡0=110,D⁡y⁡0=0
We can then obtain the solution as:
dsol1≔dsolve⁡dsysuniondini,numeric
dsol1 ≔ procx_rkf45_dae...end proc
dsol1⁡12
t=0.500000000000000,λ⁡t=4.89750023467855,x⁡t=0.0319392699415791,ⅆⅆtx⁡t=0.000564539406239432,y⁡t=−0.999489811490763,ⅆⅆty⁡t=0.0000180384378593043
dsol1⁡1
t=1.,λ⁡t=4.90499905723651,x⁡t=0.000360891517794992,ⅆⅆtx⁡t=−0.0999937504894365,y⁡t=−0.999999934755133,ⅆⅆty⁡t=−0.0000360794101890703
Solution with rosenbrock_dae:
dsol2≔dsolve⁡dsysuniondini,numeric,method=rosenbrock_dae
dsol2 ≔ procx_rosenbrock_dae...end proc
dsol2⁡12
t=0.500000000000000,λ⁡t=4.89750019118586,x⁡t=0.0319392364763694,ⅆⅆtx⁡t=0.000564626004686083,y⁡t=−0.999489813543334,ⅆⅆty⁡t=0.0000180482728717227
dsol2⁡1
t=1.,λ⁡t=4.90499906207811,x⁡t=0.000360968463263150,ⅆⅆtx⁡t=−0.0999936779452163,y⁡t=−0.999999936691318,ⅆⅆty⁡t=−0.0000360897908606990
Solution with mebdfi:
dsol3≔dsolve⁡dsysuniondini,numeric,method=mebdfi
dsol3 ≔ procx_mebdfi...end proc
dsol3⁡12
t=0.500000000000000,λ⁡t=4.89749908804820855,x⁡t=0.0319389748677520596,ⅆⅆtx⁡t=0.000565199414553933343,y⁡t=−0.999489820801930273,ⅆⅆty⁡t=0.0000180581765179766362
dsol3⁡1
t=1.,λ⁡t=4.90499581413915475,x⁡t=0.000361181747066772996,ⅆⅆtx⁡t=−0.0999926673290293111,y⁡t=−0.99999993019115307,ⅆⅆty⁡t=−0.0000360957473722881540
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⁡y1⁡t,t,t+9.8+2⁢λ1⁡t⁢y1⁡t+2⁢λ2⁡t⁢y1⁡t−y2⁡t,diff⁡x1⁡t,t,t+2⁢λ1⁡t⁢x1⁡t+2⁢λ2⁡t⁢x1⁡t−x2⁡t,x1⁡t−x2⁡t2+y1⁡t−y2⁡t2−14,x1⁡t2+y1⁡t2−1,diff⁡y2⁡t,t,t+9.8−2⁢λ2⁡t⁢y1⁡t−y2⁡t,diff⁡x2⁡t,t,t−2⁢λ2⁡t⁢x1⁡t−x2⁡t
dsysd≔ⅆ2ⅆt2x2⁡t−2⁢λ2⁡t⁢x1⁡t−x2⁡t,x1⁡t−x2⁡t2+y1⁡t−y2⁡t2−14,x1⁡t2+y1⁡t2−1,ⅆ2ⅆt2x1⁡t+2⁢λ1⁡t⁢x1⁡t+2⁢λ2⁡t⁢x1⁡t−x2⁡t,ⅆ2ⅆt2y2⁡t+9.8−2⁢λ2⁡t⁢y1⁡t−y2⁡t,ⅆ2ⅆt2y1⁡t+9.8+2⁢λ1⁡t⁢y1⁡t+2⁢λ2⁡t⁢y1⁡t−y2⁡t
ics≔x1⁡0=0,x2⁡0=0,y1⁡0=−1,y2⁡0=−32,D⁡x1⁡0=−3,D⁡x2⁡0=4,D⁡y1⁡0=0,D⁡y2⁡0=0
dsold≔dsolve⁡dsysdunionics,numeric
dsold ≔ procx_rkf45_dae...end proc
The trajectory of the second mass can be plotted via:
plotsodeplot⁡dsold,x2⁡t,y2⁡t,0..5,numpoints=1000
Note that we did not specify initial conditions for λ1⁡t and λ2⁡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[ck45]
dsolve[Events]
dsolve[maxfun]
dsolve[mebdfi]
dsolve[numeric,interactive]
dsolve[numeric,IVP]
dsolve[numeric]
dsolve[rkf45]
dsolve[rosenbrock]
dsolve[Stiffness]
plots[odeplot]
Download Help Document