Problem with ODE45
显示 更早的评论
Hallo, I wrote code on ODE45. I want to record the event at a condition (pasted in the code). The code is as follows.
y1_init = 0; y2_init = 0; ph_init = 0; vy1=0;vy2=2;wz=0;
x_init = [y1_init; y2_init; ph_init]; v_init= [vy1; vy2; wz]; acc_init = [0; 0; 0];
w_init = [x_init; v_init]; wp_init = [v_init; acc_init];
opts = odeset('RelTol',1e-3,'AbsTol',1e-3,'Events',@events);
[t,y,te,ye,ie] = ode45(@expl,[0 30],w_init,[],Mdash,Qdash,Pdash,hdash,s0dash,opts);
teout = [teout; te];
yeout = [yeout; ye];
ieout = [ieout; ie];
% where Mdash, Qdash,Pdash, hdash,s0dash are matrices I defined earlier.
%Below is the ode function
function dydt = expl(t,y,Mdash,Qdash,Pdash,hdash,s0dash,opts)
dydt = [y(4:6);(Mdash^(-1)*hdash)-(Mdash^(-1)*Qdash*y(1:3))];
end
% below is the vent function
function [value,isterminal,direction] = events(t,y)
value = y(5)-1.9999;
isterminal =1;
direction =0; end
Everything works fine without the definitions of event. But I want to stop the ode at some point (the variable 'value' in event function). But it throws me an error at the main function.
The below is the error.
Error in ode45 (line 78) solver_name = 'ode45';
Output argument "varargout{4}" (and maybe others) not assigned during call to "C:\Program Files\MATLAB\R2012a\toolbox\matlab\funfun\ode45.m>ode45".
Error in Peicewise_ODE_v5 (line 40) [t,y,te,ye,ie] = ode45(@expl,[0 30],w_init,[],Mdash,Qdash,Pdash,hdash,s0dash,opts);
Any Inputs? I don't understand what is the mistake I did.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!