How to find the maximum of a variable within a function ?
Afficher commentaires plus anciens
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
Réponses (1)
Star Strider
le 29 Sep 2012
Modifié(e) : Star Strider
le 29 Sep 2012
0 votes
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 commentaire
Lakshmi
le 29 Sep 2012
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!