Info

This question is closed. Reopen it to edit or answer.

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 view (last 30 days)
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

Answers (1)

Cris LaPierre
Cris LaPierre on 27 Oct 2020
Edited: Cris LaPierre on 27 Oct 2020
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!