How to find the maximum of a variable within a function ?

Hi,
My question is, suppose I have a function like the following (got this eg. from MATLAB ODE solver help)
function dy = rigid(t,y)
dy = zeros(3,1); % a column vector
dy(1) = y(2) * y(3);
dy(2) = -y(1) * y(3);
dy(3) = -0.51 * y(1) * y(2);
I solve for this system of ODEs using the ode45 solver.
But suppose I'd like to find the maximum of one of the variables say y(1) within the function rigid.m and then say for instance, dy(2)= -max(y(1)) * y(3), how do i do it? Specifying, max(y(1)) within the function rigid.m doesn't seem to work in calculating the maximum value of the variable y(1).
I'd appreciate any help with this. Thanks, Lakshmi

2 comentarios

Jose
Jose el 29 de Sept. de 2012
You want max(y(1)) be the maximum value calculated until the moment or during all integration interval?
Lakshmi
Lakshmi el 29 de Sept. de 2012
Hi Jose,
I want max(y(1)) to be constant during all the integration interval.
Thanks, Lakshmi

Iniciar sesión para comentar.

Respuestas (1)

Star Strider
Star Strider el 29 de Sept. de 2012
Editada: Star Strider el 29 de Sept. de 2012
See odeset, (specifically the ODE Events Property) and Event Location and Advanced Event Location for details.
The example in Advanced Event Location seems to be able to do what you want. You will have to adapt the events function for the orbitode example, but it seems to perform the sort of detection you describe.
I haven't used the 'Events' option myself recently, so I leave you to experiment with it.

1 comentario

Lakshmi
Lakshmi el 29 de Sept. de 2012
I am also not familiar with odeset. Let me take a look at it. Thanks for the suggestion.
Lakshmi

Iniciar sesión para comentar.

Preguntada:

el 28 de Sept. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by