How can I get MATLAB to solve a system of equations containing differential and algebraic equations?

4 visualizzazioni (ultimi 30 giorni)
I have a system of about 40 equations, about half are ordinary differential equations (that must be solved numerically), the other half are simple algebraic equations, but all rely on variables solved for in the other type. I have been trying to use ode45 to solve the system, but the variables solved for in alegraic equations do not update with time steps, even though the variables used to calculate them are changing. For example, if i have dx1/dt = t, x2 = x1+5, and I use t=0:10, x1 changes with t, but x2 remains constant, even though it should change with x1. Has anybody else had this problem or know a way around it?

Risposta accettata

Adam
Adam il 2 Lug 2013
Marc,
Thanks for your help. I've never used a mass matrix before and I have a couple of questions. First, how do I determine the index of my DAE (I thought it was only 1, but MATLAB is telling me it appears to be greater than 1)? Each equation contains only first derivatives, but they also contain other variables and first derivatives (e.g. dx3 = x3 + 4*x1 + 2*dx2). Since after looking at some information on indices of DAEs I'm pretty sure mine is greater than 1 and thus not solvable using MATLAB (or at least ODE15s), do you have any suggestions of programs that actually do this?
  1 Commento
Marc
Marc il 12 Lug 2013
Modificato: Marc il 12 Lug 2013
Without seeing your system, I cannot comment. If you do not supply ode15s with the correct mass matrix, you will most likely get some error about your DAE being of index greater than one.
The most basic check is that the number of equations are equal to the number of unknowns you are solving for but this doesn't always guarantee you index 1.
Unfortunately, it is not straight forward. There are multiple definitions for index.
I typically use ode15s and Sundials cvode and ida. The sundials ode solvers for Matlab are very nice but I don't recall if IDA can handle higher indexes.
Another long shot is LIMEX, but again, not sure on on higher indexes.
Overall, on my simpler stuff, ode15s, cvode and ida seem to give good agreement. Limex on one system of pdes turned DAE gives good agreement with ode15s. This is by no means a comprehensive review....
Sorry, your just going to have to roll up your sleeves, grab the closest bottle of scotch and dig in...

Accedi per commentare.

Più risposte (1)

Marc
Marc il 29 Giu 2013
See ODE15s documentation on this and you will want to define your mass matrix as being either constant or as a function call within the ODE options. Torsten gave a good example of this in the newsgroup. Search there. If I find it, I will post the link.
If your mass matrix is not constant and it sounds like it is not, you will need to define a function massMat...... And use the @massMat in the options to let ode15s know to use this.

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by