iteration

1 次查看(过去 30 天)
mohamed saber
mohamed saber 2011-11-12
plz .... why there is no answer in this iteration when i use this input by order :
30 , .01 ,1 1000 ,18,.02 ,1.2 ,1200, 2 , .05 , .75 , 1400
clear , clc
fprintf(' \n <<< this program calculate Q in three branched pipes from three tanks >>> \n %12.5f ')
fprintf (' \n 1- Data for highest tank \n %12.5f')
% Data for highest tank
E1=input ('\n Enter tank_ energy (m) : ');
f1=input (' Enter pipe_friction coefficient (m) : ');
d1=input (' Enter pipe_diameter (m) : ');
l1=input (' Enter pipe_length (m) : ');
fprintf (' \n 2- Data for intermediate tank \n %12.5f ')
% Data for intermediate tank
E2=input ('\n Enter tank_ energy (m) : ');
f2=input (' Enter pipe_friction coefficient (m) : ');
d2=input (' Enter pipe_diameter (m) : ');
l2=input (' Enter pipe_length (m) : ');
fprintf (' \n 3- Data for lower tank \n %12.5f ')
% Data for lower tank
E3=input ('\n Enter tank_ energy (m) : ');
f3=input (' Enter pipe_friction coefficient (m) : ');
d3=input (' Enter pipe_diameter (m) : ');
l3=input (' Enter pipe_length (m) : ');
% resistance calculation
R1=(.8*f1*l1)/(9.8*d1^5); % 1st pipe resistance
R2=(.8*f2*l2)/(9.8*d2^5); % 2nd pipe resistance
R3=(.8*f3*l3)/(9.8*d3^5); % 3rd pipe resistance
% junction's energy assumption (Ej)
Ej=(E1+E3)/2; % E1 <Ej< E3
% Q calculation
Q1=((abs(E1-Ej))/(R1))^.5;
Q2=((abs(E2-Ej))/(R2))^.5;
Q3=((abs(E3-Ej))/(R3))^.5;
% Q enter to j is +ve , Q out from j is -ve
if E2<Ej % Q in 2nd pipe is -ve
dQ=Q1-Q2-Q3; % applying sign law
elseif E2>Ej % Q in 2nd pipe is +ve
dQ=Q1+Q2-Q3; % applying sign law
end
if dQ>0 % if dQ +ve ... increase Ej
iter=0;
while abs(dQ)>.0001 % tolerrance
Ej=Ej+.001; % increase Ej
iter=iter+1; % no of try & error
q1=((abs(E1-Ej))/(R1))^.5;
q2=((abs(E2-Ej))/(R2))^.5;
q3=((abs(E3-Ej))/(R3))^.5;
if Ej>E2
dQ=q1-q2-q3;
else
dQ=q1+q2+q3;
end
end
fprintf('\n Q at 1st pipe(m^3/s)= %12.5f\n ',q1)
fprintf('\n Q at 2nd pipe(m^3/s)= %12.5f\n ',q2)
fprintf('\n Q at 3rd pipe(m^3/s)= %12.5f\n ',q3)
fprintf('\n Energy at junction(m)= %12.5f\n ',Ej)
fprintf('\n no.of iteration= %12.5f\n',iter)
elseif dQ<0; % if dQ +ve ... decrease Ej
iter=0;
while abs(dQ)>.0001 % tolerrance
Ej=Ej-.001; % decrease Ej
iter=iter+1; % no of try & error
q1=((abs(E1-Ej))/(R1))^.5;
q2=((abs(E2-Ej))/(R2))^.5;
q3=((abs(E3-Ej))/(R3))^.5;
if Ej>E2
dQ=q1-q2-q3;
else
dQ=q1+q2+q3;
end
end
fprintf('\n Q at 1st pipe(m^3/s)= %12.5f\n ',q1)
fprintf('\n Q at 2nd pipe(m^3/s)= %12.5f\n ',q2)
fprintf('\n Q at 3rd pipe(m^3/s)= %12.5f\n ',q3)
fprintf('\n Energy at junction(m^3/s)= %12.5f\n ',Ej)
fprintf('\n no.of iteration(m^3/s)= %12.5f\n',iter)
end
generally , the program run well when (E1+E3)/2 >E2 but it doesn't run when (E1+E3)/2 >E2
please , help me

回答(1 个)

Jan
Jan 2011-11-13
You can use the debugger to check, what's going on: Open the file in the editor, set a breakpoint after the input commands and step through the program line by line.
Working with the debugger is more efficient than asking the forum.

类别

Help CenterFile Exchange 中查找有关 Model Statistics 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by