MatLab ODE start/stop conditions

…衆ロ難τιáo~ 提交于 2019-12-01 12:34:44

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.

Add the function

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

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

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

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);...]

Hope this helps.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!