Changing the value of only one parameter causes a problem (possibly with while loop)
Hello everyone. Firstly, as I do not have access to my other computer right now, I am using the online compiler, if that makes any difference (but I do not think so). In the attaced code, in the first section, when I set the d(1:10) value to 0.04, it just can’t proceed further after the while loop and keeps calculating forever, as seen in screenshot (1). At least I assume so; the thing is, I haven’t used matlab much and when I open the debugger (screenshot(2)) and step in and continue, it keeps doing the while loop over and over again. Overall, I do not get any crucial error that seemingly affect the working mechanism of the code: Only "consider preallocating for speed suggestions", so I cannot understand what is wrong with it. By the way, this happens as the value gets smaller: When d is smaller than 0.07. When I set it to something like 150, it still works. What might be the reasoon?
Thanks in advance!
%% Constants and Assumptions
g=9.81;
hgelgit=0.5;
he=0.3;
Vmin=0.6;
Vmax=0.9;
f=0.03;
s=0.25;
Cq(1)=0.61;
rho0=1008.301;
rhoa=998.83;
H=20;
Lana=1500;
d(1:10)=0.04;
hf(1)=0;
%% Initial Hydraulic Head
h=(rhoa*(H+hgelgit+he))/(rho0);
E(1)=h-H;
%% First Port
a(1)=pi*(d(1))^2./4;
q(1)=Cq(1)*a(1)*sqrt(2*g*E(1));
Q(1)=q(1);
D(1)=floor(20*(sqrt(4*Q(1)/(pi*Vmin))))/20;
A(1)=pi*D(1)^2./4;
V(1)=Q(1)/(pi*(D(1)^2./4)); %[m/s]
hizyuk(1)=0;
U(1)=q(1)/(pi*d(1)^2./4);
Dmax(1)=(sqrt(4*Q(1)/(pi*Vmin)));
Dmin(1)=(sqrt(4*Q(1)/(pi*Vmax)));
%% Other Ports
for i=2:10
hf(i)=f*(s/D(i-1))*(V(i-1)^2./(2*g));
E(i)=E(i-1)+hf(i);
Cq(i)=0.63-0.58*(((V(i-1))^2)/(2*g*E(i)));
a(i)=pi*(d(i))^2./4;
x=cumsum(a);
q(i)=Cq(i)*a(i)*sqrt(2*g*E(i));
Q(i)=Q(i-1)+q(i);
Dmax(i)=(sqrt(4*Q(i)/(pi*Vmin)));
Dmin(i)=(sqrt(4*Q(i)/(pi*Vmax)));
D(i)=D(i-1);
A(i)=pi*D(i)^2./4;
V(i)=Q(i)/(pi*(D(i)^2./4));
hizyuk(i)=V(i-1)^2./(2*g*E(i));
while (V(i) >= Vmax)
D(i)=floor(20*(sqrt(4*Q(i)/(pi*Vmin))))/20;
V(i)=Q(i)/(pi*(D(i)^2./4));
end
U(i)=q(i)/(pi*d(i)^2./4);
end
y=x./(pi*D.^2./4);
%% Results
results=zeros(10,16);
results(:,1)=transpose(hf);
results(:,2)=transpose(E);
results(:,3)=transpose(hizyuk);
results(:,4)=transpose(Cq);
results(:,5)=transpose(a);
results(:,6)=transpose(x);
results(:,7)=transpose(q);
results(:,8)=transpose(U);
results(:,9)=transpose(Q);
results(:,10)=transpose(Dmin);
results(:,11)=transpose(Dmax);
results(:,12)=transpose(D);
results(:,13)=transpose(A);
results(:,14)=transpose(y);
results(:,15)=transpose(V);
results(:,16)=transpose(Q)*1000;
max(q)/min(q)
resultsHello everyone. Firstly, as I do not have access to my other computer right now, I am using the online compiler, if that makes any difference (but I do not think so). In the attaced code, in the first section, when I set the d(1:10) value to 0.04, it just can’t proceed further after the while loop and keeps calculating forever, as seen in screenshot (1). At least I assume so; the thing is, I haven’t used matlab much and when I open the debugger (screenshot(2)) and step in and continue, it keeps doing the while loop over and over again. Overall, I do not get any crucial error that seemingly affect the working mechanism of the code: Only "consider preallocating for speed suggestions", so I cannot understand what is wrong with it. By the way, this happens as the value gets smaller: When d is smaller than 0.07. When I set it to something like 150, it still works. What might be the reasoon?
Thanks in advance!
%% Constants and Assumptions
g=9.81;
hgelgit=0.5;
he=0.3;
Vmin=0.6;
Vmax=0.9;
f=0.03;
s=0.25;
Cq(1)=0.61;
rho0=1008.301;
rhoa=998.83;
H=20;
Lana=1500;
d(1:10)=0.04;
hf(1)=0;
%% Initial Hydraulic Head
h=(rhoa*(H+hgelgit+he))/(rho0);
E(1)=h-H;
%% First Port
a(1)=pi*(d(1))^2./4;
q(1)=Cq(1)*a(1)*sqrt(2*g*E(1));
Q(1)=q(1);
D(1)=floor(20*(sqrt(4*Q(1)/(pi*Vmin))))/20;
A(1)=pi*D(1)^2./4;
V(1)=Q(1)/(pi*(D(1)^2./4)); %[m/s]
hizyuk(1)=0;
U(1)=q(1)/(pi*d(1)^2./4);
Dmax(1)=(sqrt(4*Q(1)/(pi*Vmin)));
Dmin(1)=(sqrt(4*Q(1)/(pi*Vmax)));
%% Other Ports
for i=2:10
hf(i)=f*(s/D(i-1))*(V(i-1)^2./(2*g));
E(i)=E(i-1)+hf(i);
Cq(i)=0.63-0.58*(((V(i-1))^2)/(2*g*E(i)));
a(i)=pi*(d(i))^2./4;
x=cumsum(a);
q(i)=Cq(i)*a(i)*sqrt(2*g*E(i));
Q(i)=Q(i-1)+q(i);
Dmax(i)=(sqrt(4*Q(i)/(pi*Vmin)));
Dmin(i)=(sqrt(4*Q(i)/(pi*Vmax)));
D(i)=D(i-1);
A(i)=pi*D(i)^2./4;
V(i)=Q(i)/(pi*(D(i)^2./4));
hizyuk(i)=V(i-1)^2./(2*g*E(i));
while (V(i) >= Vmax)
D(i)=floor(20*(sqrt(4*Q(i)/(pi*Vmin))))/20;
V(i)=Q(i)/(pi*(D(i)^2./4));
end
U(i)=q(i)/(pi*d(i)^2./4);
end
y=x./(pi*D.^2./4);
%% Results
results=zeros(10,16);
results(:,1)=transpose(hf);
results(:,2)=transpose(E);
results(:,3)=transpose(hizyuk);
results(:,4)=transpose(Cq);
results(:,5)=transpose(a);
results(:,6)=transpose(x);
results(:,7)=transpose(q);
results(:,8)=transpose(U);
results(:,9)=transpose(Q);
results(:,10)=transpose(Dmin);
results(:,11)=transpose(Dmax);
results(:,12)=transpose(D);
results(:,13)=transpose(A);
results(:,14)=transpose(y);
results(:,15)=transpose(V);
results(:,16)=transpose(Q)*1000;
max(q)/min(q)
results Hello everyone. Firstly, as I do not have access to my other computer right now, I am using the online compiler, if that makes any difference (but I do not think so). In the attaced code, in the first section, when I set the d(1:10) value to 0.04, it just can’t proceed further after the while loop and keeps calculating forever, as seen in screenshot (1). At least I assume so; the thing is, I haven’t used matlab much and when I open the debugger (screenshot(2)) and step in and continue, it keeps doing the while loop over and over again. Overall, I do not get any crucial error that seemingly affect the working mechanism of the code: Only "consider preallocating for speed suggestions", so I cannot understand what is wrong with it. By the way, this happens as the value gets smaller: When d is smaller than 0.07. When I set it to something like 150, it still works. What might be the reasoon?
Thanks in advance!
%% Constants and Assumptions
g=9.81;
hgelgit=0.5;
he=0.3;
Vmin=0.6;
Vmax=0.9;
f=0.03;
s=0.25;
Cq(1)=0.61;
rho0=1008.301;
rhoa=998.83;
H=20;
Lana=1500;
d(1:10)=0.04;
hf(1)=0;
%% Initial Hydraulic Head
h=(rhoa*(H+hgelgit+he))/(rho0);
E(1)=h-H;
%% First Port
a(1)=pi*(d(1))^2./4;
q(1)=Cq(1)*a(1)*sqrt(2*g*E(1));
Q(1)=q(1);
D(1)=floor(20*(sqrt(4*Q(1)/(pi*Vmin))))/20;
A(1)=pi*D(1)^2./4;
V(1)=Q(1)/(pi*(D(1)^2./4)); %[m/s]
hizyuk(1)=0;
U(1)=q(1)/(pi*d(1)^2./4);
Dmax(1)=(sqrt(4*Q(1)/(pi*Vmin)));
Dmin(1)=(sqrt(4*Q(1)/(pi*Vmax)));
%% Other Ports
for i=2:10
hf(i)=f*(s/D(i-1))*(V(i-1)^2./(2*g));
E(i)=E(i-1)+hf(i);
Cq(i)=0.63-0.58*(((V(i-1))^2)/(2*g*E(i)));
a(i)=pi*(d(i))^2./4;
x=cumsum(a);
q(i)=Cq(i)*a(i)*sqrt(2*g*E(i));
Q(i)=Q(i-1)+q(i);
Dmax(i)=(sqrt(4*Q(i)/(pi*Vmin)));
Dmin(i)=(sqrt(4*Q(i)/(pi*Vmax)));
D(i)=D(i-1);
A(i)=pi*D(i)^2./4;
V(i)=Q(i)/(pi*(D(i)^2./4));
hizyuk(i)=V(i-1)^2./(2*g*E(i));
while (V(i) >= Vmax)
D(i)=floor(20*(sqrt(4*Q(i)/(pi*Vmin))))/20;
V(i)=Q(i)/(pi*(D(i)^2./4));
end
U(i)=q(i)/(pi*d(i)^2./4);
end
y=x./(pi*D.^2./4);
%% Results
results=zeros(10,16);
results(:,1)=transpose(hf);
results(:,2)=transpose(E);
results(:,3)=transpose(hizyuk);
results(:,4)=transpose(Cq);
results(:,5)=transpose(a);
results(:,6)=transpose(x);
results(:,7)=transpose(q);
results(:,8)=transpose(U);
results(:,9)=transpose(Q);
results(:,10)=transpose(Dmin);
results(:,11)=transpose(Dmax);
results(:,12)=transpose(D);
results(:,13)=transpose(A);
results(:,14)=transpose(y);
results(:,15)=transpose(V);
results(:,16)=transpose(Q)*1000;
max(q)/min(q)
results matlab, while loop, debugger MATLAB Answers — New Questions