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 Ansichten (letzte 30 Tage)
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)

Antworten (2)

Walter Roberson
Walter Roberson am 22 Okt. 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

VBBV
VBBV am 22 Okt. 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 Kommentare
VBBV
VBBV am 22 Okt. 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
VBBV am 22 Okt. 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)
The diameter ratio is 0.0476
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)
The orfice area is 1963.4954 mm^2
P = PD*248.64107 ;
fprintf('The pressure difference is %.4f Pa ',P)
The pressure difference is 298.3693 Pa
mu = -0.245*T^2 + 474.4*T +1.75*10^5 ;
fprintf('The absolute viscosity is %.4f kg/m s ',mu)
The absolute viscosity is 186706.8750 kg/m s
p = BP/(Rc*(T + 273.15)) ;
fprintf('The air density is %.4f kg/m^3 ',p)
The air density is 1.1803 kg/m^3
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
iteration no 1
The mass flow rate is 32969.3195 kg/s
The volumetric flow rate is 27932.2114 m^3/s
iteration no 2
The mass flow rate is 32856.8967 kg/s
The volumetric flow rate is 27836.9647 m^3/s
iteration no 3
The mass flow rate is 32759.3527 kg/s
The volumetric flow rate is 27754.3237 m^3/s
iteration no 4
The mass flow rate is 32673.7854 kg/s
The volumetric flow rate is 27681.8295 m^3/s
iteration no 5
The mass flow rate is 32598.0164 kg/s
The volumetric flow rate is 27617.6366 m^3/s
iteration no 6
The mass flow rate is 32530.3758 kg/s
The volumetric flow rate is 27560.3302 m^3/s
iteration no 7
The mass flow rate is 32469.5608 kg/s
The volumetric flow rate is 27508.8066 m^3/s
iteration no 8
The mass flow rate is 32414.5386 kg/s
The volumetric flow rate is 27462.1908 m^3/s
iteration no 9
The mass flow rate is 32364.4792 kg/s
The volumetric flow rate is 27419.7796 m^3/s
iteration no 10
The mass flow rate is 32318.7076 kg/s
The volumetric flow rate is 27381.0011 m^3/s
iteration no 11
The mass flow rate is 32276.6683 kg/s
The volumetric flow rate is 27345.3846 m^3/s
iteration no 12
The mass flow rate is 32237.9001 kg/s
The volumetric flow rate is 27312.5394 m^3/s
iteration no 13
The mass flow rate is 32202.0163 kg/s
The volumetric flow rate is 27282.1380 m^3/s
iteration no 14
The mass flow rate is 32168.6904 kg/s
The volumetric flow rate is 27253.9037 m^3/s
iteration no 15
The mass flow rate is 32137.6444 kg/s
The volumetric flow rate is 27227.6010 m^3/s
iteration no 16
The mass flow rate is 32108.6402 kg/s
The volumetric flow rate is 27203.0281 m^3/s
iteration no 17
The mass flow rate is 32081.4725 kg/s
The volumetric flow rate is 27180.0111 m^3/s
iteration no 18
The mass flow rate is 32055.9631 kg/s
The volumetric flow rate is 27158.3991 m^3/s
iteration no 19
The mass flow rate is 32031.9569 kg/s
The volumetric flow rate is 27138.0606 m^3/s
disp(R)
290

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by