Event Location ode求解器的事件属性

ode求解器的事件属性


检测事件


matlab微分方程如何设定变量的范围 

dy1=y2
dy2=y1+1
其中y1的范围为0<y1<=4

【解】


M文件:
function [value,isterminal,direction] events1(t,y)
value y(1)-4;
isterminal= 1;
direction 0;

命令窗口:
dy @(t,y) [y(2);y(1) 1];
options=odeset('events',@events1);
[t,y] ode45(dy,[0 12],[0 1],options);
plot(t,y)




Description of Event Location Properties


Events— The functionis of the form


[value,isterminal,direction] events(t,y)


value, isterminal, and directionarevectors for which the ith element corresponds tothe ith event function: 


  • value(i)  is the value of the it hevent function.


  • isterminal(i)=  if  the integration is to terminate at zero of this event function,otherwise, 0. 


  • direction(i)    if all zeros areto be located (the default), 

  • +1    if only zeros wherethe event function is increasing, 

  • and -1   if onlyzeros where the event function is decreasing. 


If you specify an events function and events are detected, thesolver returns three additional outputs:

  • column vector of times at whichevents occur

  • Solution values corresponding to these times

  • Indices into the vector returned by the events function.The values indicate which event the solver detected.


If you call the solver as 

[T,Y,TE,YE,IE] solver(odefun,tspan,y0,options)

the solver returns these outputs as TE, YE,and IErespectively. 


If you call the solver as 

sol solver(odefun,tspan,y0,options)

the solver returns these outputs as sol.xe, sol.ye,and sol.ie, respectively.


For examples that use an event function, see and in the MATLAB Mathematics documentation.


........................


编写events.m文件描述需要检测的事件(过零点检测):


function [value,isterminal,direction]=events(t,x)


事件检查函数,此时需要做的是过零点检测
Y=x(3);
ode45函数自动检查当value=0是否成立
在此问题上我们要求检测Y=0的点,因此设置value=Y
如果我们要检测Y=2,那么就设置value=Y-2

value=Y;


检测到指定条件时,是否终止ode45函数的运行
1表示终止,0表示继续
在我们这个问题上,我们只要检测到零点时就停止程序

isterminal=1;


value过零点检测的方向
-1表示由正到负,+1表示由负到正
对于我们这个问题,当然是由正到负
direction=-1;
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值