Implementing while loop in Heun's Method

2 ビュー (過去 30 日間)
Nisrina Younes
Nisrina Younes 2022 年 11 月 12 日
編集済み: Alan Stevens 2022 年 11 月 12 日
For dh/dt=-k√H where k is = 0.06
how can I implement while loop (while H>0) in Heun's method to find the time taken for the tank to drain ?. given the initial value of H is 4
Thanks for the help in advance

回答 (1 件)

Alan Stevens
Alan Stevens 2022 年 11 月 12 日
編集済み: Alan Stevens 2022 年 11 月 12 日
Here's a rough and ready way (I'll leave you to implement Heun's method):
f = @(H) -0.06*sqrt(H);
H = 4;
t = 0;
dt = 0.1; % choose your own value
while H>0
t = t+dt;
% Use Heun's method to get H at t+dt
end
disp(t) % time to drain
Note that, because of the square root, the last step is likely to result in a complex value for the final value of H.

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by