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

답변 (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