try&erorr

2 次查看(过去 30 天)
mohamed saber
mohamed saber 2011-11-10
i want to ask how can i make try&erorr with reasonable erorr the program is 3 tanks have a different energy .. and they connected together by pipe .. this pipe meet togethrt at point j the iteration is to get the energy at j (Ej) .. and then find the flow rate (Q) at each pipe theoretical summtion of Q at j equal 0
this is the program but it has an erorr
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;
if E2<Ej
Qtot=Q1-Q2-Q3;
end
% iteration
if Qtot>0
err=1;
iter=0;
while abs(err)>.001
iter=iter+1;
Ej=Ej+.1;
Q1=((abs(E1-Ej))/(R1))^.5;
Q2=((abs(E2-Ej))/(R2))^.5;
Q3=((abs(E3-Ej))/(R3))^.5;
Qtot=Q1-Q2-Q3;
err=Qtot;
end
end
  1 个评论
Jan
Jan 2011-11-10
Please use a proper code formatting as explained at the "Markup help" link. Currently your code is not readable.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2011-11-10
It isn't clear to me that the required error tolerance is certain to be satisfied when Ej is incremented by a constant value. Shouldn't you be doing some zero-crossing detection to zero in on proper Ej ? You could arrange it as an fzero or fmincon optimization.

类别

Help CenterFile Exchange 中查找有关 Fluid Dynamics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by