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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by