Info

この質問は閉じられています。 編集または回答するには再度開いてください。

when i do my code for v>0 on my while loop it's a neverending loop and i dont know why if i do it for i<30 for 30 iterations i get a height of 50784 but should be right around 205.7 any ideas how to stop it from entering an ifinite loop on v>0 and a

5 ビュー (過去 30 日間)
Mitchell McKinney
Mitchell McKinney 2020 年 10 月 27 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
clear;
h=60 %stepsize
hof=240 %inches in water
dtank=120 %diameter of tank in inches
dnozzle=1.049 %diameter of nozzle in inches
areanozzle=((dnozzle^2)*pi)/4 %area of nozzle
areaoftank=((dtank^2)*pi)/4 %area of tank
v=areaoftank*hof %initial volume of water in tank
c=.6 %tank discharge coefficiant
g=386.088 %force of gravity
b=dnozzle/dtank %beta
baseball=-areanozzle*c*(sqrt((2*g)/((1-b^4)*(areaoftank))))
F =@(x,y) (x * sqrt(y)); %function
i=0
while i<30
i=i+1;
k1=F(baseball,v)
k2=F(baseball + .5*h,v + .5*h*k1)
k3=F(baseball + .5*h,v + .5*h*k2)
k4=F(baseball + .5*h,v + h*k3)
v=v+ (1/6) *(k1 + 2*k2 + 2*k3 + k4)*h
if v<0
break
end
end
v
seconds=i*h/60
height=v/areaoftank

回答 (1 件)

Cris LaPierre
Cris LaPierre 2020 年 10 月 27 日
編集済み: Cris LaPierre 2020 年 10 月 27 日
It's infinite because your condintion, v>0, would always be true.
Programming-wise, your code does not create an error. That means you should make sure you have properly implemented your equations and algorithms correctly.

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by