Introduce a while loop ina ode45 resolution
14 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Lancelot Ribot
am 13 Jul. 2017
Kommentiert: Lancelot Ribot
am 13 Jul. 2017
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.
0 Kommentare
Akzeptierte Antwort
Jan
am 13 Jul. 2017
Bearbeitet: Jan
am 13 Jul. 2017
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!