Start / Stop Conditions for MATLAB ODE

I have a little problem. I have 2 equations of motion 'ph' and 'ph2' I don’t know how to set ODE to stop the calculation of “ph” when x (1)> 0.111, and then again starts to calculate “ph2” only to 0.111, after which the graph of 'ph' + 'ph2' per graph depends on the time of 'w' I think I need to set some time limits, but I don’t know how to do it. I use HELP but have no benefit to me.

[t,y] = ode45(@ph,[0,w_max],[0,0]);

function dx = ph(tt,x)
global F1 c m_c Ff p w s ln f_t sig dstr Ren pn Fex Fzmax xz xn l Fz mn
Fpp = F1 + c*x(1);

if pn<0
 pn=abs(pn);
end

if x(1)<ln

    pn=spline(w,p,tt)-((2*sig)/dstr*Ren);    
    Fex=3.1416.*f_t.*pn.*(ln-x(1));
end

if x(1)<42e-5
     Fz = Fzmax*(1-(1/xz)*(x(1)+l));   
end

if x(1)>44e-3
    m_c=m_c-mn;
end
dx=[x(2);((spline(w,p,tt)*s)-Fpp-Ff-Fex-Fz)./m_c];


[t2,y2] = ode45(@ph2,[0,w_max],[0,0]);

function dx=ph2(tt,x)

    global Fv m_c g f alfa Fzp c m_nbp

    Ft=m_c*g*f;
    Fv = 2*f*(Fzp/cos(alfa));

    if x(1)>0.44

    m_c=m_c+m_nbp

    end

    dx = [x(2);((x(1)*c)-Ft-Fv)/m_c];
+1
source share
1 answer

ph x(1) > 0.111, ( , ). , , 0, ode45 .

function [value,isterminal,direction] = events(t,y)
% Locate the time when y passes through 0.111 in all 
% directions and stop integration.
value = y(1) - 0.111;  % Detect y=0.111
isterminal = 1;        % Stop the integration
direction = 0;         % All direction

options = odeset('Events',@events)

[t,y] = ode45(@ph,[0,w_max],[0,0],options);

, ph- dx=[x(2); ...], x (1), - - dx=[x(1); x(2);...]

, .

+4

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


All Articles