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!