Need help fixing my ODE45 script

1 回表示 (過去 30 日間)
Stevon Kline
Stevon Kline 2019 年 11 月 1 日
コメント済み: Stevon Kline 2019 年 11 月 2 日
My teacher tried helping me build this code for a falling object with resistance. (We did it on paper since we didn't have a computer near at the time.) Given only the acceleration a = g+kv2. With y(0) = 1000, and v(0) = 0. Need to find the time, and velocity when object hits the ground.
I'm getting empty sets as my outputs....suggestions?
h = 1000;
t0 = 0; tfinal = 15;
tspan = [t0,tfinal];
options = odeset('Events',@landing);
[t,y,te,ye,ie] = ode45(@drag,tspan,[h;0],options);
function dydt = drag(t,y)
k = 1/10;
g = 9.8;
dydt = [-y(2); g + k*-(y(2)).^2];
end
function [check,stop,direction]=landing(t,y)
check = y(1);
stop = 1;
direction=0;
end
  1 件のコメント
darova
darova 2019 年 11 月 1 日
Works ok for me
img1.png

サインインしてコメントする。

採用された回答

Takumi
Takumi 2019 年 11 月 1 日
Since you want to detect when the position becomes zero, the correct description is as follows.
check = y(1);
  3 件のコメント
Takumi
Takumi 2019 年 11 月 1 日
Change the value of tfinal to about 150 seconds (it takes about 100 seconds to hit the ground) and check the value of te and ye (2) when the calculation is complete .These are the time and velocity when the object hits the ground respectively.
Stevon Kline
Stevon Kline 2019 年 11 月 2 日
Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by