Introduce a while loop ina ode45 resolution

조회 수: 14 (최근 30일)
Lancelot Ribot
Lancelot Ribot 2017년 7월 13일
댓글: Lancelot Ribot 2017년 7월 13일
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