keeping track of a quantity in an ODE system

57 Views Asked by At

I have looked at some Maple help documents, but it was hard to find what I wanted to do..

My situation is quite simple. I have a couple ODE for (say) 5 variables,

$a_1 '(t) = a_2 (t) a_3(t) - a_1 (t)^2 $, $a_2 '(t) = ...$, (some quadratic expression) ..., $a_5'(t) = ...$.

And I want to numerically keep track of a quantity, say, the energy

$E(t)=\sum_i a_i^2 (t)$ as a function of time, given initial data.

Is there a simple Maple or Mathematica code to do this?

1

There are 1 best solutions below

3
On BEST ANSWER

Maple's dsolve will numerically solve a differential-algebraic initial-value problem (DAE IVP) just as readily as it will solve a system of ODEs. You simply need to include your $E(t)$ equation in the system. Example:

ODEs:= diff(a1(t),t) = a2(t) - a1(t)^2, diff(a2(t),t) = a1(t) - a2(t):
EQs:= E(t) = add(a||i(t)^2, i= 1..2):
ICs:= a1(0)=1, a2(0)=2:
Sol:= dsolve({ODEs, EQs, ICs}, [seq(a||i(t), i= 1..2), E(t)], numeric):

Sol(1.);
Maple's response:
[t = 1., a1(t) = 1.24710625783968, a2(t) = 1.50536853378559, E(t) = 3.82140844085815]