Problem with ODE45
15 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Torsten
2016 年 11 月 9 日
Change the following lines:
[t,y,te,ye,ie] = ode45(@(t,y)expl(t,y,Mdash,Qdash,Pdash,hdash,s0dash),[0 30],w_init,opts);
...
function dydt = expl(t,y,Mdash,Qdash,Pdash,hdash,s0dash)
dydt = [y(4:6);(Mdash^(-1)*hdash)-(Mdash^(-1)*Qdash*y(1:3))];
end
Best wishes
Torsten.
2 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!