Code is running continuously, but never ends
3 views (last 30 days)
Show older comments
h_s=[1 2 5 6];
h_d = [3 4 8 6];
MA = [3.5 1.5 2.5];
D_d = 0.0254*[1.25 1.75 2.25];
D_s = [0.03175 0.04445 0.05715];
D_p = 0.0254*[2.5 3.5 4.5];
L = [0.10 0.18 0.16];
for k1 = 1:numel(h_s) % suction head m
for k2 = 1:numel(h_d) % delivery head m
for k3 = 1:numel(MA) % mechanical advantage
for k4 = 1:numel(D_d) %delivery pipe diameter
for k5 = 1:numel(D_s) %suction pipe diamter...0.0254*[1.25 1.75 2.25]
for k6 = 1:numel(D_p) %piston diameter m
for k7 = 1:numel(L)% height of cylinder stoke
y=[0.15 0.094]
%yv = linspace(min(y), max(y), 10);
v0 = 0.01;
m =64.5;
x = 0.7;
b = 0.625;
a = 0.250;
g = 9.8;
[A_d(k4,:)] = (D_d(k4)^2)*3.14*0.25;
for a1= 1:numel(A_d)
[A_s(k5,:)] = (D_s(k5)^2)*3.14*.25;
for a2= 1:numel(A_s)
l_d = 4.572;
l_s = 6.096;
[A_p(k6,:)] = ((D_p(k6))^2)*3.14*0.25;
for a3= 1:numel(A_p)
m_p = 0.2;
rho = 1000;
uk = 0.06;
uf = 0.4;
up = 0.00089;
h = 0.001;
t_w= 0.05;
[A_w(k6,:)] = t_w*D_p(k6)*3.14;
for a4= 1:numel(A_w)
[z(k3,:)]=(0.2946*MA(k3)-0.1761);
for a5= 1:numel(z)
M_tr= 2;
L_tr=0.5;
P=173.7;
R_pin=0.05;]
[M_T(k7,k3,a1,a3,a5,:)]=2*m_p*(A_d(a1)/A_p(a3))^2+(L(k7)+l_d+l_s)*rho*((A_d(a1))^2/A_p(a3))+(2*M_tr*L_tr^2/a^2)+(z(a5))^2*MA(k3)^2*m*(A_d(a1)/A_p(a3))^2;
for a6= 1:numel(M_T)
[c0(a3,a1,a6,:)]=((1-2*x)*A_p(a3)*P/(A_d(a1)*M_T(a6)));
disp(c0);
for t0 = 1:numel(c0)
[c1(k1,k2,k7,k3,a2,a1,a3,a6,:)]=(rho*g*((h_s(k1))*A_s(a2)+(h_d(k2))*A_d(a1)+(L(k7))*A_p(a3))+z(+1)*m*g*MA(k3))/M_T(a6);
for t1 = 1:numel(c1)
[c2(a3,a6,:)]=(2*rho*g*A_p(a3))/M_T(a6);
for t2 = 1:numel(c2)
[c3(a1,a6,a3,k7,:)]=(2*uf*b+25.12*up*L(k7)*h)*A_d(a1)/(h*M_T(a6)*A_p(a3));
for t3 = 1:numel(c3)
[c4(k4,k5,a1,a2,a6,:)]=(0.124*rho^0.75*up^0.25*[l_d*D_d(k4)^0.25+l_s*D_s(k5)^0.25]*(A_d(a1)/A_s(a2))^1.75)/M_T(a6);
for t4 = 1:numel(c4)
[c5(a1,a2,a3,a6,:)]=rho*[((A_d(a1))^2/A_s(a2))*[0.5+0.5+0.2+0.4+0.5]+0.5*((A_d(a1))^2/A_p(a3))+A_d(a1)*(0.5+0.4+0.2+1)+0.5*((A_d(a1))^2/A_p(a3))]/(2*M_T(a6));%please check the constants.
for t5 = 1:numel(c5)
[y,v(t0,t1,t2,t3,t4,t5,:)] = ode45((@(y,v)((c0(t0)/v^2)-(c1(t1)/v)-(c2(t2)*y/v)-c3(t3)-c4(t4)*v^0.75-c5(t5)*v)) ,y ,v0);
%disp(v,y) % displays y and x_velocity
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
end
%% I am not able to get output and the code is not showing any error.
%% It is going to run for long time.
%% Please, upload this into your matlab tool, then you can have idea of problem. Please, tell me how to proceed.
6 Comments
Walter Roberson
on 2 Sep 2019
Go to the MATLAB command line and give the command
doc waitbar
and read what shows up.
Answers (1)
Guillaume
on 2 Sep 2019
As others have said, you need to debug the code you've written, using the various tools that matlab offer. waitbar is one, you could also use the debugger to step through your problem line by line.
I would suspect that the code is not even doing what you meant it to do. As Adam said you have an extremely large number of nested loops and some of them don't make much sense. For example, we have
%inside the k1, k2, k3, ..., k6, k7 loops
[A_d(k4,:)] = (D_d(k4)^2)*3.14*0.25;
for a1= 1:numel(A_d)
%...
Note that this code is inside the k5, k6 and k7 loops, yet doesn't depend at all on these indices. So for a start the whole calculation will be repeated max(k5)*max(k6)*max(k7) times each time yielding the exact same result. Certainly a waste of time, but not the biggest problem.
The right hand side of the equation is always going to be scalar, so the : on the left hand side is misleading. It's equivalent to 1. We also have some unnecessary [] brackets. None of this is a problem, but it makes me wonder if something was intended all along.
The biggest problem is that A_d grows at each step of the k4 loop. When k4 is 1, A_d is only one element, then when k4 is 2, you add a new element as A_d(2), etc. So, the number of steps that the a1 loop is going to take depends on the current k4. I'm fairly certain that was not the intent.
6 Comments
Guillaume
on 3 Sep 2019
"I want to select different interval for each loop"
For y? If so, simply define y inside the loops as
y = linspace(0, L(k7), 20);
However if y is a vector, then your if y < ... and if y > ... (and what happens when y = ... ?) don't make any sense.
But more importantly, I don't understand what the purpose of y is. Your ode is supposed to solve
but the y you've created is not used by the ode (it's a completely different y variable internal to the solver). If the value of c1 is supposed to change within the ode depending on the y internal to the solver then you'll have to completely change the ode design.
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!