Hello, I am working on a matlab code for school and it is using a while loop. The problem with this is I want the while loop to run until the variable doesn't equal itself.
23 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
So the code won't change the value of R for the while loop which I do not understand. Along with this, in the while loop it has a big if statment with two varriables unkown. A randomly selected value for R is imput and needs to run until it R converges and gives the output of that R and the Cop# that whent with what PT you went with.
Here is the long code with the while loop portion at the top and me trying to get the output for R at the bottom.
% Inputs
D = input('What is the Duct Diameter in mm? \n') ; % Input that asks for the Duct Diameter in mm
d = input('What is the Orifice Diameter in mm? \n') ;
PD = input('What is the Pressure Difference in " W.C.? \n') ;
BP = input('What is the Barometric Pressure in Pa? \n') ;
T = input('What is the Ambient Temperature in °C? \n') ;
R = input('What is the initial guess for the Reynolds number? \n') ;
PT = input('What kind of Pressure Tap is being used? Enter 1 for Corner Tap, 2 for Flange Tap, 3 for D-D/2 Tap or 4 for an ISA-1932 Nozzle. \n') ; % Input that asks what type of tap or nozzle is being used
B = d/D ;
fprintf('The diameter ratio is %.4f ',B)
A = ((19000*B)/(R)).^0.8; % Area that will change based on B and R resulting in mm^2
Rc = 287 ;
A0 = pi*(d/2)^2 ;
fprintf('The orfice area is %.4f mm^2 ',A0)
P = PD*248.64107 ;
fprintf('The pressure difference is %.4f Pa ',P)
mu = -0.245*T^2 + 474.4*T +1.75*10^5 ;
fprintf('The absolute viscosity is %.4f kg/m s ',mu)
p = BP/(Rc*(T + 273.15)) ;
fprintf('The air density is %.4f kg/m^3 ',p)
while R ~= R
R = R + 0.1 ;
if PT == 1 % If PT is equal to 1 then a Corner Tap is being used
L1 = 0; % L1 is given in the textbook based on the tap used (page 25 ASME)
L2 = 0; % L2 is given in the textbook based on the tap used (page 25 ASME)
m = ((2*(L2))/(1 - B)); % m is given based on the L values and the Diameter Ratio
if (D >= 71.12)
Cop1 = 0.5961 + (0.0261*(B.^2)) - (0.216*(B.^8)) + 0.000521*((((10.^6)*B)/R).^0.7) + ((0.0188 + 0.0063*A)*(B.^3.5)*(((10.^6)/R).^0.3)) + (0.043 + 0.080*(exp(-10*(L1))) - 0.123*(exp((-7)*L1)))*(1 - 0.11*A)*((B.^4)/(1-B.^4)) - 0.031*((m) - (0.8*(m).^(1.1)))*B.^1.3 ; % Cop1 calculates the Discharge Coefficcient for a Corner Tap with a Diameter more than 71.12 mm
mr1 = Cop1*A0/(sqrt(1 - B^4))*sqrt(2*P*p) ;
fprintf('The mass flow rate is %.4f kg/s ', mr1)
qv1 = mr1/p ;
fprintf('The volumetric flow rate is %.4f m^3/s ',qv1)
if (B >= .1) && (B < .2) % If statement used to caculate uncertainty
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop1, (0.7 - B)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .2) && (B < .6) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f with an uncertainty of 0.50%% \n', Cop1) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .6) && (B < .75) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop1, ((1.6667*B) - .5)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
end
elseif (D < 71.12)
Cop1 = 0.5961 + (0.0261*(B.^2)) - (0.216*(B.^8)) + 0.000521*((((10.^6)*B)/R).^0.7) + ((0.0188 + 0.0063*A)*(B.^3.5)*(((10.^6)/R).^0.3)) + (0.043 + 0.080*(exp(-10*(L1))) - 0.123*(exp((-7)*L1)))*(1 - 0.11*A)*((B.^4)/(1-B.^4)) - 0.031*((m) - (0.8*(m).^(1.1)))*B.^1.3 + 0.011*(0.75 - B)*(2.8 - D/25.4) ; % Cop1 calculates the Discharge Coefficcient for a Corner Tap with a Diameter less than 71.12 mm
mr1 = Cop1*A0/(sqrt(1 - B^4))*sqrt(2*P*p) ;
fprintf('The mass flow rate is %.4f kg/s ', mr1)
qv1 = mr1/p ;
fprintf('The volumetric flow rate is %.4f m^3/s ',qv1)
if (B >= .1) && (B < .2) % If statement used to caculate uncertainty
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop1, (0.7 - B) + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .2) && (B < .6) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f with an uncertainty of %.2f % \n', Cop1, 0.5 + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .6) && (B < .75) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop1, ((1.6667*B) - 0.5) + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
end
end
elseif PT == 3 % If PT is equal to 3 then a D or D/2 tap is being used
L1 = 1; % L1 is given in the textbook based on the tap used (page 25 ASME)
L2 = .47; % L2 is given in the textbook based on the tap used (page 25 ASME)
m = ((2*(L2))/(1 - B)); % m is given based on the L values and the Diameter Ratio
if (D >= 71.12)
Cop3 = 0.5961 + (0.0261*(B.^2)) - (0.216*(B.^8)) + 0.000521*((((10.^6)*B)/R).^0.7) + ((0.0188 + 0.0063*A)*(B.^3.5)*(((10.^6)/R).^0.3)) + (0.043 + 0.080*(exp(-10*(L1))) - 0.123*(exp((-7)*L1)))*(1 - 0.11*A)*((B.^4)/(1-B.^4)) - 0.031*((m) - (0.8*(m).^(1.1)))*B.^1.3 ; % Cop3 calculates the discharge coefficcient for D or D/2 taps with a Diameter greater than 71.12 mm
mr3 = Cop3*A0/(sqrt(1 - B^4))*sqrt(2*P*p) ;
fprintf('The mass flow rate is %.4f kg/s ', mr3)
qv3 = mr3/p ;
fprintf('The volumetric flow rate is %.4f m^3/s ',qv3)
if (B >= .1) && (B < .2) % If statement used to caculate uncertainty
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop3, (0.7 - B)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .2) && (B < .6) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f with an uncertainty of 0.50%% \n', Cop3) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .6) && (B < .75) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop3, ((1.6667*B) - .5)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
end
elseif (D < 71.12)
Cop3 = 0.5961 + (0.0261*(B.^2)) - (0.216*(B.^8)) + 0.000521*((((10.^6)*B)/R).^0.7) + ((0.0188 + 0.0063*A)*(B.^3.5)*(((10.^6)/R).^0.3)) + (0.043 + 0.080*(exp(-10*(L1))) - 0.123*(exp((-7)*L1)))*(1 - 0.11*A)*((B.^4)/(1-B.^4)) - 0.031*((m) - (0.8*(m).^(1.1)))*B.^1.3 + 0.011*(0.75 - B)*(2.8 - D/25.4) ; % Cop3 calculates the Discharge Coefficcient for D or D/2 taps with a Diameter less than 71.12 mm
mr3 = Cop3*A0/(sqrt(1 - B^4))*sqrt(2*P*p) ;
fprintf('The mass flow rate is %.4f kg/s ', mr3)
qv3 = mr3/p ;
fprintf('The volumetric flow rate is %.4f m^3/s ',qv3)
if (B >= .1) && (B < .2) % If statement used to caculate uncertainty
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop3, (0.7 - B) + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .2) && (B < .6) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f with an uncertainty of %.2f % \n', Cop3, 0.5 + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .6) && (B < .75) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop3, ((1.6667*B) - .5) + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
end
end
elseif PT == 2 % If PT is equal to 2 then a Flange Tap is being used
L1 = (25.4/D); % L1 is given in the textbook based on the tap used (page 25 ASME)
L2 = (25.4/D); % L1 is given in the textbook based on the tap used (page 25 ASME)
m = ((2*(L2))/(1-B)); % m is given based on the L values and the Diameter Ratio
if (D >= 71.12)
Cop2 = 0.5961 + (0.0261*(B.^2)) - (0.216*(B.^8)) + 0.000521*((((10.^6)*B)/R).^0.7) + ((0.0188 + 0.0063*A)*(B.^3.5)*(((10.^6)/R).^0.3)) + (0.043+0.080*(exp(-10*(L1))) - 0.123*(exp((-7)*L1)))*(1 - 0.11*A)*((B.^4)/(1 - B.^4)) - 0.031*((m) - (0.8*(m).^(1.1)))*B.^1.3 ; % Cop2 calculates the discharge coefficcient for flange taps with a Diameter greater than 71.12 mm
mr2 = Cop2*A0/(sqrt(1 - B^4))*sqrt(2*P*p) ;
fprintf('The mass flow rate is %.4f kg/s ', mr2)
qv2 = mr2/p ;
fprintf('The volumetric flow rate is %.4f m^3/s ',qv2)
if (B >= .1) && (B < .2) % If statement used to caculate uncertainty
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop2, (0.7 - B)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .2) && (B < .6) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f with am uncertainty of 0.50%% \n', Cop2) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .6) && (B < .75) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop2, ((1.6667*B) - .5)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
end
elseif (D < 71.12)
Cop2 = 0.5961 + (0.0261*(B.^2)) - (0.216*(B.^8)) + 0.000521*((((10.^6)*B)/R).^0.7) + ((0.0188 + 0.0063*A)*(B.^3.5)*(((10.^6)/R).^0.3)) + (0.043 + 0.080*(exp(-10*(L1))) - 0.123*(exp((-7)*L1)))*(1 - 0.11*A)*((B.^4)/(1-B.^4)) - 0.031*((m) - (0.8*(m).^(1.1)))*B.^1.3 + 0.011*(0.75 - B)*(2.8 - D/25.4) ; % Cop2 calculates the Discharge Coefficcient for flange taps with a Diameter less than 71.12 mm
mr2 = Cop2*A0/(sqrt(1 - B^4))*sqrt(2*P*p) ;
fprintf('The mass flow rate is %.4f kg/s ', mr2)
qv2 = mr2/p ;
fprintf('The volumetric flow rate is %.4f m^3/s ',qv2)
if (B >= .1) && (B < .2) % If statement used to caculate uncertainty
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop2, (0.7 - B) + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .2) && (B < .6) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f with am uncertainty of %.2f % \n', Cop2, 0.5 + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .6) && (B < .75) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop2, ((1.6667*B) - .5) + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
end
end
elseif PT == 4 % If PT is equal to 4 than a ISA-1932 Nozzel is being used
Cop4 = 0.9900 - 0.2262*(B).^4.1 - (0.00175*B.^2 - 0.0033*B^4.15)*((10.^6)/R).^1.15 ; % Calculates the discharge coefficient if you are using a ISA-1932 Nozzle
mr4 = Cop4*A0/(sqrt(1 - B^4))*sqrt(2*P*p) ;
fprintf('The mass flow rate is %.4f kg/s ', mr4)
qv4 = mr4/p ;
fprintf('The volumetric flow rate is %.4f m^3/s ',qv4)
if B <= .6 % If statement used to caculate uncertainty
fprintf('The discharge coefficient is %.4f with an uncertainty of 0.80%% \n', Cop4) % Outputs a statement with your discharge coefficient and uncertainty based on your diameter ratio
elseif B > .6 % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop4, ((2*B) - .4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
end
end
end
disp(R)
0 commentaires
Réponses (2)
Walter Roberson
le 22 Oct 2024
while R ~= R
That R ~= R will only be true if R is NaN.
I want the while loop to run until the variable doesn't equal itself.
Possibly you want to store the previous version, into something like R_old, and test R ~= R_old and inside the loop,
R_old = R;
R = something that updates R
0 commentaires
VBBV
le 22 Oct 2024
while R ~= Rc
You probably need to change the while loop condition like above. Given the input value for Reynolds number you need to check it against its critical value which i presume as Rc
2 commentaires
VBBV
le 22 Oct 2024
You may also add another condition in case user inputs R value exactly as 287.
if isequal(R, Rc) fprintf('message') else while R~=Rc ... end end
VBBV
le 22 Oct 2024
% Inputs
D = 1050; %input('What is the Duct Diameter in mm? \n') ; % Input that asks for the Duct Diameter in mm
d = 50; %input('What is the Orifice Diameter in mm? \n') ;
PD = 1.2; %input('What is the Pressure Difference in " W.C.? \n') ;
BP = 101000;%input('What is the Barometric Pressure in Pa? \n') ;
T = 25; %input('What is the Ambient Temperature in °C? \n') ;
R = 100; %input('What is the initial guess for the Reynolds number? \n') ;
PT = 1; %input('What kind of Pressure Tap is being used? Enter 1 for Corner Tap, 2 for Flange Tap, 3 for D-D/2 Tap or 4 for an ISA-1932 Nozzle. \n') ; % Input that asks what type of tap or nozzle is being used
B = d/D ;
fprintf('The diameter ratio is %.4f ',B)
A = ((19000*B)/(R)).^0.8; % Area that will change based on B and R resulting in mm^2
Rc = 287 ;
A0 = pi*(d/2)^2 ;
fprintf('The orfice area is %.4f mm^2 ',A0)
P = PD*248.64107 ;
fprintf('The pressure difference is %.4f Pa ',P)
mu = -0.245*T^2 + 474.4*T +1.75*10^5 ;
fprintf('The absolute viscosity is %.4f kg/m s ',mu)
p = BP/(Rc*(T + 273.15)) ;
fprintf('The air density is %.4f kg/m^3 ',p)
k = 1;
while R ~= Rc & R <= Rc
R = R + 10 ; % for convenience stp size is increased
fprintf('iteration no %d ', k) % record iteration
if PT == 1 % If PT is equal to 1 then a Corner Tap is being used
L1 = 0; % L1 is given in the textbook based on the tap used (page 25 ASME)
L2 = 0; % L2 is given in the textbook based on the tap used (page 25 ASME)
m = ((2*(L2))/(1 - B)); % m is given based on the L values and the Diameter Ratio
if (D >= 71.12)
Cop1 = 0.5961 + (0.0261*(B.^2)) - (0.216*(B.^8)) + 0.000521*((((10.^6)*B)/R).^0.7) + ((0.0188 + 0.0063*A)*(B.^3.5)*(((10.^6)/R).^0.3)) + (0.043 + 0.080*(exp(-10*(L1))) - 0.123*(exp((-7)*L1)))*(1 - 0.11*A)*((B.^4)/(1-B.^4)) - 0.031*((m) - (0.8*(m).^(1.1)))*B.^1.3 ; % Cop1 calculates the Discharge Coefficcient for a Corner Tap with a Diameter more than 71.12 mm
mr1 = Cop1*A0/(sqrt(1 - B^4))*sqrt(2*P*p) ;
fprintf('The mass flow rate is %.4f kg/s ', mr1)
qv1 = mr1/p ;
fprintf('The volumetric flow rate is %.4f m^3/s ',qv1)
if (B >= .1) && (B < .2) % If statement used to caculate uncertainty
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop1, (0.7 - B)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .2) && (B < .6) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f with an uncertainty of 0.50%% \n', Cop1) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .6) && (B < .75) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop1, ((1.6667*B) - .5)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
end
elseif (D < 71.12)
Cop1 = 0.5961 + (0.0261*(B.^2)) - (0.216*(B.^8)) + 0.000521*((((10.^6)*B)/R).^0.7) + ((0.0188 + 0.0063*A)*(B.^3.5)*(((10.^6)/R).^0.3)) + (0.043 + 0.080*(exp(-10*(L1))) - 0.123*(exp((-7)*L1)))*(1 - 0.11*A)*((B.^4)/(1-B.^4)) - 0.031*((m) - (0.8*(m).^(1.1)))*B.^1.3 + 0.011*(0.75 - B)*(2.8 - D/25.4) ; % Cop1 calculates the Discharge Coefficcient for a Corner Tap with a Diameter less than 71.12 mm
mr1 = Cop1*A0/(sqrt(1 - B^4))*sqrt(2*P*p) ;
fprintf('The mass flow rate is %.4f kg/s ', mr1)
qv1 = mr1/p ;
fprintf('The volumetric flow rate is %.4f m^3/s ',qv1)
if (B >= .1) && (B < .2) % If statement used to caculate uncertainty
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop1, (0.7 - B) + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .2) && (B < .6) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f with an uncertainty of %.2f % \n', Cop1, 0.5 + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .6) && (B < .75) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop1, ((1.6667*B) - 0.5) + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
end
end
elseif PT == 3 % If PT is equal to 3 then a D or D/2 tap is being used
L1 = 1; % L1 is given in the textbook based on the tap used (page 25 ASME)
L2 = .47; % L2 is given in the textbook based on the tap used (page 25 ASME)
m = ((2*(L2))/(1 - B)); % m is given based on the L values and the Diameter Ratio
if (D >= 71.12)
Cop3 = 0.5961 + (0.0261*(B.^2)) - (0.216*(B.^8)) + 0.000521*((((10.^6)*B)/R).^0.7) + ((0.0188 + 0.0063*A)*(B.^3.5)*(((10.^6)/R).^0.3)) + (0.043 + 0.080*(exp(-10*(L1))) - 0.123*(exp((-7)*L1)))*(1 - 0.11*A)*((B.^4)/(1-B.^4)) - 0.031*((m) - (0.8*(m).^(1.1)))*B.^1.3 ; % Cop3 calculates the discharge coefficcient for D or D/2 taps with a Diameter greater than 71.12 mm
mr3 = Cop3*A0/(sqrt(1 - B^4))*sqrt(2*P*p) ;
fprintf('The mass flow rate is %.4f kg/s ', mr3)
qv3 = mr3/p ;
fprintf('The volumetric flow rate is %.4f m^3/s ',qv3)
if (B >= .1) && (B < .2) % If statement used to caculate uncertainty
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop3, (0.7 - B)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .2) && (B < .6) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f with an uncertainty of 0.50%% \n', Cop3) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .6) && (B < .75) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop3, ((1.6667*B) - .5)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
end
elseif (D < 71.12)
Cop3 = 0.5961 + (0.0261*(B.^2)) - (0.216*(B.^8)) + 0.000521*((((10.^6)*B)/R).^0.7) + ((0.0188 + 0.0063*A)*(B.^3.5)*(((10.^6)/R).^0.3)) + (0.043 + 0.080*(exp(-10*(L1))) - 0.123*(exp((-7)*L1)))*(1 - 0.11*A)*((B.^4)/(1-B.^4)) - 0.031*((m) - (0.8*(m).^(1.1)))*B.^1.3 + 0.011*(0.75 - B)*(2.8 - D/25.4) ; % Cop3 calculates the Discharge Coefficcient for D or D/2 taps with a Diameter less than 71.12 mm
mr3 = Cop3*A0/(sqrt(1 - B^4))*sqrt(2*P*p) ;
fprintf('The mass flow rate is %.4f kg/s ', mr3)
qv3 = mr3/p ;
fprintf('The volumetric flow rate is %.4f m^3/s ',qv3)
if (B >= .1) && (B < .2) % If statement used to caculate uncertainty
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop3, (0.7 - B) + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .2) && (B < .6) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f with an uncertainty of %.2f % \n', Cop3, 0.5 + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .6) && (B < .75) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop3, ((1.6667*B) - .5) + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
end
end
elseif PT == 2 % If PT is equal to 2 then a Flange Tap is being used
L1 = (25.4/D); % L1 is given in the textbook based on the tap used (page 25 ASME)
L2 = (25.4/D); % L1 is given in the textbook based on the tap used (page 25 ASME)
m = ((2*(L2))/(1-B)); % m is given based on the L values and the Diameter Ratio
if (D >= 71.12)
Cop2 = 0.5961 + (0.0261*(B.^2)) - (0.216*(B.^8)) + 0.000521*((((10.^6)*B)/R).^0.7) + ((0.0188 + 0.0063*A)*(B.^3.5)*(((10.^6)/R).^0.3)) + (0.043+0.080*(exp(-10*(L1))) - 0.123*(exp((-7)*L1)))*(1 - 0.11*A)*((B.^4)/(1 - B.^4)) - 0.031*((m) - (0.8*(m).^(1.1)))*B.^1.3 ; % Cop2 calculates the discharge coefficcient for flange taps with a Diameter greater than 71.12 mm
mr2 = Cop2*A0/(sqrt(1 - B^4))*sqrt(2*P*p) ;
fprintf('The mass flow rate is %.4f kg/s ', mr2)
qv2 = mr2/p ;
fprintf('The volumetric flow rate is %.4f m^3/s ',qv2)
if (B >= .1) && (B < .2) % If statement used to caculate uncertainty
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop2, (0.7 - B)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .2) && (B < .6) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f with am uncertainty of 0.50%% \n', Cop2) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .6) && (B < .75) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop2, ((1.6667*B) - .5)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
end
elseif (D < 71.12)
Cop2 = 0.5961 + (0.0261*(B.^2)) - (0.216*(B.^8)) + 0.000521*((((10.^6)*B)/R).^0.7) + ((0.0188 + 0.0063*A)*(B.^3.5)*(((10.^6)/R).^0.3)) + (0.043 + 0.080*(exp(-10*(L1))) - 0.123*(exp((-7)*L1)))*(1 - 0.11*A)*((B.^4)/(1-B.^4)) - 0.031*((m) - (0.8*(m).^(1.1)))*B.^1.3 + 0.011*(0.75 - B)*(2.8 - D/25.4) ; % Cop2 calculates the Discharge Coefficcient for flange taps with a Diameter less than 71.12 mm
mr2 = Cop2*A0/(sqrt(1 - B^4))*sqrt(2*P*p) ;
fprintf('The mass flow rate is %.4f kg/s ', mr2)
qv2 = mr2/p ;
fprintf('The volumetric flow rate is %.4f m^3/s ',qv2)
if (B >= .1) && (B < .2) % If statement used to caculate uncertainty
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop2, (0.7 - B) + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .2) && (B < .6) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f with am uncertainty of %.2f % \n', Cop2, 0.5 + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
elseif (B >= .6) && (B < .75) % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop2, ((1.6667*B) - .5) + 0.9*(0.75 - B)*(2.8 - D/25.4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
end
end
elseif PT == 4 % If PT is equal to 4 than a ISA-1932 Nozzel is being used
Cop4 = 0.9900 - 0.2262*(B).^4.1 - (0.00175*B.^2 - 0.0033*B^4.15)*((10.^6)/R).^1.15 ; % Calculates the discharge coefficient if you are using a ISA-1932 Nozzle
mr4 = Cop4*A0/(sqrt(1 - B^4))*sqrt(2*P*p) ;
fprintf('The mass flow rate is %.4f kg/s ', mr4)
qv4 = mr4/p ;
fprintf('The volumetric flow rate is %.4f m^3/s ',qv4)
if B <= .6 % If statement used to caculate uncertainty
fprintf('The discharge coefficient is %.4f with an uncertainty of 0.80%% \n', Cop4) % Outputs a statement with your discharge coefficient and uncertainty based on your diameter ratio
elseif B > .6 % Elseif statment if prior statment was untrue
fprintf('The discharge coefficient is %.4f \n with an uncertainty of %.2f % \n', Cop4, ((2*B) - .4)) % Gives a statement with the calculated Discharge Coefficient and uncertainty based on the Diameter Ratio used
end
end
k=k+1;
end
disp(R)
Voir également
Catégories
En savoir plus sur Parallel for-Loops (parfor) dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!