24小时热门版块排行榜    

查看: 995  |  回复: 1

mathda

新虫 (小有名气)

[求助] matlab 求脉冲微分方程

程序代码运行出错,求教
function predprey
a=0.25;b=-0.01;c=-1.0;d=0.01; impcount=0;
Y=-1.2*c/d; p=0.2; tstar=0; tfinal=100;
while true
if (impcount ==0 )
options = ddeset('Events',@events,'AbsTol',1e-9,...
'RelTol',1e-9);
[t,y] = ode15s(@ddes,[tstar,tfinal],[80,30], options);
plot(y(:,1),y(:,2));
else
% Specify the new solution at impulse times...
options = ddeset(options, 'InitialY',...
[(1-p).*y(:,1); y(:,2)]);
[t,y] = ode15s(@ddes, [tstar,tfinal],...
[(1-p).*y(:,1);y(:,2)],options);
plot(y(:,1),y(:,2));
end
tstar = max(t);
impcount = impcount + 1;
if (tstar >= tfinal)
break;
end
end
%===Nested functions==============================
% Evaluate the DDES...
function dydt = ddes(t,y)
dydt = [a*y(1)+b*y(1)*y(2); ...
c*y(2)+d*y(1)*y(2)];
end
% Evaluate the event function residuals...
function [value,isterminal,direction] = events(t,y)
value = y(1)-Y;
isterminal = 1;
direction = 1;
end
end
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

csgt0

荣誉版主 (著名写手)

彩色挂图

【答案】应助回帖

感谢参与,应助指数 +1
else里面的初始y设置错误,第一次计算的结果y应该是多行2列,在else里再整列调用赋给方程的初值就错了。应该选取一行吧?
showmethemoney
2楼2012-11-01 16:30:44
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 mathda 的主题更新
信息提示
请填处理意见