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
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!