Finding Feature Highs Using ODE45

I am trying to find the locations of one of the equations in a system of differential equations in MATLAB. I am trying to use Events propety of odeset. How do I select a specific equation in my function?

options = odeset('Events',@event);
[t x tm xm ie] = ode45(@Lorenz,[0 200],I,options);


function X = Lorenz(t,x)
r = 15;
sigma = 10;
b = 8/3;
X(1,1) = sigma*(x(2,1)-x(1,1));
X(2,1) = r*(x(1,1)) - x(2,1) -x(1,1)*x(3,1);
X(3,1) = x(1,1)*x(2,1) - b*x(3,1);
end

function [value,isterminal,direction] = event(t,x)
value  = Lorenz(t,x); %I can't specify X(3,1) here
isterminal = 0;
direction = -1;
end

In particular, I try to write whenever X (3,1) = 0.

thanks

+2
source share
2 answers

Basically, looking at the documentation , if you are interested to see when x (3) = 0, then you need to rewrite the function of the event:

function [value,isterminal,direction] = event(t,x)
value  = x(3); %I can't specify X(3,1) here --> why not?? Lorenz(t,x) is going to return the differential. That not what you want
isterminal = 0;
direction = 0; %The desired directionality should be "Detect all zero crossings"
end

Now I donโ€™t know how you identified Iin

[t x tm xm ie] = ode45(@Lorenz,[0 200],I,options);

, , x (3) .

[t x tm xm ie] = ode45(@khal,[0 5],[10 -1 -20],options);
tm =

    0.1085

enter image description here

+1

, , . , , .. . , ( - ) , . , value = Lorenz(t,x), ODE , x(3). .

:

function [value,isterminal,direction] = event(t,x)
b = 8/3;
value = x(1)*x(2)-b*x(3); % The third equation from Lorenz(t,x) 
isterminal = 0;
direction = -1;

, :

function [value,isterminal,direction] = event(t,x)
y = Lorenz(t,x); % Evaluate all three equations to get third one
value = y(3);
isterminal = 0;
direction = -1;

, :

function [value,isterminal,direction] = event(t,x)
value = Lorenz(t,x);
isterminal = [0;0;0];
direction = [-1;-1;-1];

, , xm. , , , isterminal 1 xm.

, :

r = 15;
sigma = 10;
b = 8/3;
f = @(t,x)Lorenz(t,x,r,sigma,b);

I = [1;5;10];
options = odeset('Events',@(t,x)event(t,x,b));

[t,x,tm,xm,ie] = ode45(f,[0;10],I,options);

:

function X = Lorenz(t,x,r,sigma,b)
...

function [value,isterminal,direction] = event(t,x,b)
...
+1

Source: https://habr.com/ru/post/1607832/


All Articles