MatLab ODE启动/停止条件 [英] MatLab ODE start/stop conditions

查看:915
本文介绍了MatLab ODE启动/停止条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题.我有两个运动方程"ph"和"ph2" 我不知道如何在x(1)> 0.111时将ODE设置为停止计算ph,然后再次将ph2和ph2绘制到一张图上,然后再次将ph2再次计算为0.111.时间"w",我想我必须设置一些时间限制,但不知道该怎么做.我使用HELP,但对我没有好处.

I have a small problem. I have 2 equation of motion 'ph' and 'ph2' I don´t know how to set ODE to stop calculating 'ph' when x(1)> 0.111 and then starts to calculated 'ph2' again only to 0.111, after that plot 'ph' + 'ph2' to one graph depend on time 'w' i think I have to set some time limitations but dont know how to. I use HELP but no benefit for 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];

推荐答案

要在x(1) > 0.111时停止计算ph,您可以使用事件位置属性(

To stop calculating ph when x(1) > 0.111 you can use the Event location property (manual page and example on how to use it). In practice it's a function evaluated at each time step and if the value returned is 0, then ode45 stops the integration.

添加功能

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)进行设置

And set it by options = odeset('Events',@events) before calling

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

但是鉴于ph输出dx=[x(2); ...],为了检查x(1),您还需要输出该变量-类似于dx=[x(1); x(2);...]

But given that ph outputs dx=[x(2); ...], in order to do a check on x(1) you need to output also that variable - something like dx=[x(1); x(2);...]

希望这会有所帮助.

这篇关于MatLab ODE启动/停止条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆