help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: function writing in differential equations


From: John W. Eaton
Subject: Re: function writing in differential equations
Date: Tue, 14 Oct 2008 15:18:36 -0400

On 14-Oct-2008, genehacker wrote:

| 
| Thanx for the replies. So I directly put in the functional form in other
| equations as it has to be as you mentioned.
| Now I dont understand whether I have to use DAE or ODE solver. I have been
| thinking of DAE because I have 'time-dependent variables' that are a
| function of other variables in the model, 
| 
| So, If I have the following system of 6 equations:
| 
| xdot(1) = 0.5 * exp(-10*t) - x(4) * x(1);
| xdot(2) = x(5) * 0.5 - x(6) * x(2);
| xdot(3) = x(6) * x(2) - 0.5 * x(3);
| x(4) = 0.5- ((0.5- 0.1)/(1 + (x(1)/5)));
| x(5) = 0.5- ((0.5- 0.1)/(1 + (x(1)/5)));
| x(6) = 0.1-((0.1- 0.5)/(1 + (x(1)/5)));
| 
| If x(4) = f(x(1)) is regarded as an algebraic equation, and x(4) is
| time-dependent and influences x(1), I would think there are two approaches
| to solve the problem and I have two questions in them.
| 
| 1) Treat the system as DAE and use dassl to solve. But it requires to
| specify xdot0! Do we need to specify this at all? Isn't it over-solving the
| problem with more constraints? Is there a way not to specify x0 and still
| use dassl?

To write your set of equations above in a form suitable for dassl (or
probably better, daspk, which is a later revision of dassl) you will
need to write them as:

  res(1) = xdot(1) - 0.5 * exp(-10*t) - x(4) * x(1);
  res(2) = xdot(2) - x(5) * 0.5 - x(6) * x(2);
  res(3) = xdot(3) - x(6) * x(2) - 0.5 * x(3);
  res(4) = x(4) - 0.5- ((0.5- 0.1)/(1 + (x(1)/5)));
  res(5) = x(5) - 0.5- ((0.5- 0.1)/(1 + (x(1)/5)));
  res(6) = x(6) - 0.1-((0.1- 0.5)/(1 + (x(1)/5)));

What is your initial condition?  You are correct that for best
results, it should be consistent, and dassl tends to have difficulty
if it is not.  If you use daspk, it has some options for attempting to
compute a consisten set of initial conditions (see "help
daspk_options" for details).  For example, I think you would need to
set

  daspk_options ("compute consistent initial condition", 1);
  daspk_options ("algebraic variables", [0, 0, 0, 1, 1, 1]);

before calling daspk.  With these settings, daspk can solve this
problem

  t = 0:0.1:10;
  x0 = zeros (6, 1);
  xdot0 = zeros (6, 1);

  [x, xdot, istate, msg] = daspk (@rhs, x0, xdot0, t);

and you can plot it with

  plot (t, x)

though your system of equations appears to be unstable (at least from
this initial condition).

| Ps: I dont care about derivates of x(4),x(5) and x(6)

You'll get them as part of the solution to the DAE system.

jwe


reply via email to

[Prev in Thread] Current Thread [Next in Thread]