Introduce a while loop ina ode45 resolution

14 次查看(过去 30 天)
Hello, I am a new user of Matlab and I am facing difficulties while trying to introduce a while loop in a differential resolution. My code is this one :
function [dy] = vdp1(t,y,Vent)
Cx0 = 2;
Cx1 = 0.8;
Syz = 2;
Sxz = 2;
Sxy = 2;
S1 = 75;
tf1 = 4;
m = 15;
M = 80;
Latitude = 69.5;
dy = zeros (6,1);
D = (sqrt(y(1)^2 + y(2)^2 + y(3)^2))/(2*(m+M));
dy(1) = -1.225*Cx0*Syz*D*y(1) + 2*10^(-5)*sind(Latitude)*y(2) - 2*10^(-5)*cosd(Latitude)*y(3);
dy(4)= y(1);
dy(2) = -1.225*Cx0*Sxz*D*y(2) - 2*10^(-5)*sind(Latitude)*y(1);
dy(5) = y(2);
dy(3) = -1.225*(Cx0*Sxy + t*Cx1*S1/tf1)*D*y(3) + 2*10^(-5)*cosd(Latitude)*y(1) - 9.81;
dy(6) = y(3);
end
function [x] = Position(tf1)
x0=[77 0 -2.4 0 0 4000];
t0=0;
tfin=tf1;
[t,x] = ode45(@vdp1,[t0 tfin],x0,[]);
end
I would like to know if it is possible to insert a while loop saying something like : while y(6) is higher than a certain altitude then solve, else the resolution is over.
Thank you for all the help you could give me.

采纳的回答

Jan
Jan 2017-7-13
编辑:Jan 2017-7-13
This seems to be a job for the event function. See odeset for setting such a funtion. See also https://www.mathworks.com/help/matlab/math/ode-event-location.html.
Note: 2*10^(-5) is an expensive power operation, while 2e-5 is a cheap constant, which saves run time.
  1 个评论
Lancelot Ribot
Lancelot Ribot 2017-7-13
Thank you for your answer !! I am going to read this page carefully
P.S : thanks for the tip

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by