Function With While Loop Help

5 ビュー (過去 30 日間)
Brian Peoples
Brian Peoples 2019 年 2 月 16 日
コメント済み: Brian Peoples 2019 年 2 月 18 日
Hello--
So I need to calculate time, flow rate, height, and velocity of water exiting a cylindrical container until the container is empty. I must use a while loop within a function to do so. I am supposed to break the loop once h (height) is slightly larger than 0 so h>0. I need to define a counting variable and start at t = 0.
This is my code for the function so far:
function [Q,h,t,V] = hw4_func_BDP(Initial_Height,Outer_D,Inner_D)
p = 1000; %(kg/m^3) pressure of water
g = 9.81; %(m/s^2) acceleration due to gravity
k = ((d^2)/(D^2))*sqrt(2*g); %constant with diameters of large hole vs exit hole
%Outputs (all vectors)
t = 0 %Time
h = sqrt(h0-.5*k.*t).^2 %Fluid Height
V = sqrt(2*g.*h) %Velocity
Q = pi*(Inner_D/2)^2 .*V %Flow Rate
j = 1
while h > 0
%I am uncertain what to do here
j = j+1
end
The inputs in my script are:
h0 = 2; %initial height
D = 1; %outer diameter
d = .1; %inner diameter
Also, I am supposed to calculate these as vectors, should I define them in my script as blank vectors before hand? Like t = [] h = [] V = [] Q = []
Please help!!

採用された回答

Walter Roberson
Walter Roberson 2019 年 2 月 17 日
At each step, you can determine h (height) by knowing the current volume remaining and knowing the cross-section area of the vessel. At each step, the volume reduces by the flow rate multiplied by the time step.
  4 件のコメント
Brian Peoples
Brian Peoples 2019 年 2 月 18 日
So what is velocity equal to in this case?
Brian Peoples
Brian Peoples 2019 年 2 月 18 日
Oh and the question says we can assume pressure on the top and the bottom is 0Pa

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

その他の回答 (1 件)

Brian Peoples
Brian Peoples 2019 年 2 月 18 日
Screen Shot 2019-02-17 at 9.48.24 PM.png
  3 件のコメント
Brian Peoples
Brian Peoples 2019 年 2 月 18 日
Screen Shot 2019-02-17 at 9.48.45 PM.png
Brian Peoples
Brian Peoples 2019 年 2 月 18 日
So I am asking about e. on the third page. I can't figure this out.....

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by