Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
ode solvers and outputing dependent variables

Subject: ode solvers and outputing dependent variables

From: Erik Dambach

Date: 13 Mar, 2009 13:18:02

Message: 1 of 7

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

Subject: ode solvers and outputing dependent variables

From: Torsten Hennig

Date: 13 Mar, 2009 14:01:15

Message: 2 of 7

> 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.
Add y and z as algebraic variables to your
system of ODEs by setting the corresponding rows
of the mass matrix M to zero.
Then you can write output for them like for any
other ODE-variable.

Best wishes
Torsten.

Subject: ode solvers and outputing dependent variables

From: Erik Dambach

Date: 13 Mar, 2009 17:06:01

Message: 3 of 7

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

Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <11480465.1236952905630.JavaMail.jakarta@nitrogen.mathforum.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.
> Add y and z as algebraic variables to your
> system of ODEs by setting the corresponding rows
> of the mass matrix M to zero.
> Then you can write output for them like for any
> other ODE-variable.
>
> Best wishes
> Torsten.

Subject: ode solvers and outputing dependent variables

From: Torsten Hennig

Date: 14 Mar, 2009 12:42:32

Message: 4 of 7

> 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.
> > Add y and z as algebraic variables to your
> > system of ODEs by setting the corresponding rows
> > of the mass matrix M to zero.
> > Then you can write output for them like for any
> > other ODE-variable.
> >
> > Best wishes
> > Torsten.

Subject: ode solvers and outputing dependent variables

From: Erik Dambach

Date: 16 Mar, 2009 20:59:02

Message: 5 of 7

Great! Thank you very much for the assistance.

"Erik Dambach" <edambachremove.this@ecn.purdue.edu> wrote in message <gpdmea$4sf$1@fred.mathworks.com>...
> 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

Subject: ode solvers and outputing dependent variables

From: Steve

Date: 14 May, 2013 07:23:11

Message: 6 of 7

Hi,

I don't get how the mass matrix can have a row of zeros, since it becomes singular in that way...
Also, suppose you have
y= f3(x(1),x(2),dx(1)/dt);
Then I suppose the dx(1)/dt part would also go into the mass matrix? (This is what I have, but still, with zeros on the diagonal it becomes singular...)

Best,
Steve

Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <12469008.1237034582707.JavaMail.jakarta@nitrogen.mathforum.org>...
> > 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.
> > > Add y and z as algebraic variables to your
> > > system of ODEs by setting the corresponding rows
> > > of the mass matrix M to zero.
> > > Then you can write output for them like for any
> > > other ODE-variable.
> > >
> > > Best wishes
> > > Torsten.

Subject: ode solvers and outputing dependent variables

From: Torsten

Date: 14 May, 2013 08:14:14

Message: 7 of 7

"Steve " <lifesayko@gmail.com> wrote in message <kmsoov$h6n$1@newscl01ah.mathworks.com>...
> Hi,
>
> I don't get how the mass matrix can have a row of zeros, since it becomes singular in that way...

This is usual if the system has algebraic equations. The important point is that you have as many equations as variables you solve for.

> Also, suppose you have
> y= f3(x(1),x(2),dx(1)/dt);
> Then I suppose the dx(1)/dt part would also go into the mass matrix?

Yes. But maybe you can directly insert the expression for dx1/dt = f(x1,x2) and get an explicit equation in x(1) and x(2) for y.

(This is what I have, but still, with zeros on the diagonal it becomes singular...)
>
> Best,
> Steve
>

Best wishes
Torsten.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us