How to find the maximum of a variable within a function ?
Show older comments
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
Answers (1)
Star Strider
on 29 Sep 2012
Edited: Star Strider
on 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.
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!