```Path: news.mathworks.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!news.mathforum.org!not-for-mail
From: Torsten Hennig <Torsten.Hennig@umsicht.fhg.de>
Newsgroups: comp.soft-sys.matlab
Subject: Re: ode solvers and outputing dependent variables
Date: Sat, 14 Mar 2009 08:42:32 EDT
Organization: The Math Forum
Lines: 76
Message-ID: <12469008.1237034582707.JavaMail.jakarta@nitrogen.mathforum.org>
References: <gpe3pp\$9s9\$1@fred.mathworks.com>
NNTP-Posting-Host: nitrogen.mathforum.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: support1.mathforum.org 1237034582 14789 144.118.30.135 (14 Mar 2009 12:43:02 GMT)
X-Complaints-To: news@news.mathforum.org
NNTP-Posting-Date: Sat, 14 Mar 2009 12:43:02 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:524834

> Thank you for your input. I've been trying to
> implement the mass matrix approach but to no avail
> (using the example 'hb1dae' as a guide). from the
> example that i provided yesterday, could you possibly
> give me an example of what you mean so i can get 'y'
> out? Thanks
>

Say the complete system to solve reads
dx(1)/dt = f1(t,x(1),x(2))
dx(2)/dt = f2(t,x(1),x(2))
y = f3(t,x(1),x(2)).

Then define a problem of dimension 3,
set the mass matrix to
[1,0,0; 0,1,0; 0,0,0] (rows are seperated by ;)
and the system to
dx(1) = f1(t,x(1),x(2))
dx(2) = f2(t,x(1),x(2))
dx(3) = x(3) - f3(t,x(1),x(2))

Often it is essential that the initial condition
you provide for y are consistent, i.e. set exactly
x(3) (t=0) = f3(t=0,x(1)(t=0),x(2)(t=0)).

Best wishes
Torsten.

> Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote
> in message
> <11480465.1236952905630.JavaMail.jakarta@nitrogen.math
> forum.org>...
> > > Hello
> > >
> > > Is there any way to output dependent variables
> that
> > > are calculated within the 'ode function' or the
> > > 'event' function? For example:
> > >
> > > function dxdt = odefun(t,x)
> > > y = ugly function of t and x
> > > z = ugly function of t and x
> > > dxdt = [y*z; z];
> > >
> > > since i'm calculating the values in 'odefun', i
> want
> > > to get y and z out so i dont have to calculate
> the
> > > values again after the ode solver (ie ode23s) is
> > > done. ideally, i'd be able to get the values of y
> and
> > > z for every time step.
> > >
> > > right now the only options i see are to forgo
> using
> > > the matlab ode solver and write my own solver (i
> dont
> > > trust my ability to do this well) or to have the
> > > values written to a file each time step (doesnt
> seem
> > > very efficient).
> > >
> > > Thanks
> >
> > The ODE-solver solves systems of the form
> > M*u'=f.