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

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

댓글을 달려면 로그인하십시오.

답변 (1개)

Star Strider
Star Strider 2012년 9월 29일
편집: Star Strider 2012년 9월 29일

0 개 추천

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

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

댓글을 달려면 로그인하십시오.

카테고리

질문:

2012년 9월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by