Significant percent difference in calculated answer and code answer.
The code for a project I am doing looks like this:
% Convert flow rate to cubic feet per second
Q = Q / 448.831;
% Initial guess for Darcy friction factor f
f_guess = 0.02;
% Iterative solution for f using the Colebrook equation
maxIterations = 100000;
tolerance = 1e-6;
f_convergence = zeros(1, maxIterations);
for i = 1:maxIterations
f_next = 1 / (2 * log10(abs((epsilon/12) / (3.7) + (2.51 / (Re(Q, f_guess, mu))) / sqrt(f_guess))));
% Ensure that the friction factor is positive
f_next = max(f_next, 1e-6); % Use a small positive value if necessary
% Check for convergence
if abs(f_next – f_guess) < tolerance
f = f_next;
break;
end
f_guess = f_next;
f_convergence(i) = f_guess;
end
% Iterative solution for the diameter of the pipe using the Darcy-Weisbach equation
D_guess = 1;
D_convergence = zeros(1, maxIterations);
for i = 1:maxIterations
D_next = ((4 * f * L * Q^2) / (pi^2 * g * D_guess^5) + h_loss)^(1/5);
% Ensure that the diameter is positive
D_next = max(D_next, 1e-6); % Use a small positive value if necessary
% Check for convergence
if abs(D_next – D_guess) < tolerance
D = D_next;
break;
end
D_guess = D_next;
D_convergence(i) = D_guess;
end
This is not all of the code but this is where I am certain the error is occuring, my professors calculated result is 1.33 ft, however on I am getting an astoundingly large number of 2.36. I was wondering if there is any obvious mistakes I made in the iteration that are resulting in this.
The variables are:
Given data
Q = 4000; % Volumetric flow rate in gpm
L = 10000; % Length of the pipe in ft
h_loss = 75; % Head loss in ft
epsilon = 0.00015; % Roughness of the pipe in ft
g = 32.2; % Acceleration due to gravity in ft/s^2
mu = 0.00001; % Dynamic viscosity in ft^2/sThe code for a project I am doing looks like this:
% Convert flow rate to cubic feet per second
Q = Q / 448.831;
% Initial guess for Darcy friction factor f
f_guess = 0.02;
% Iterative solution for f using the Colebrook equation
maxIterations = 100000;
tolerance = 1e-6;
f_convergence = zeros(1, maxIterations);
for i = 1:maxIterations
f_next = 1 / (2 * log10(abs((epsilon/12) / (3.7) + (2.51 / (Re(Q, f_guess, mu))) / sqrt(f_guess))));
% Ensure that the friction factor is positive
f_next = max(f_next, 1e-6); % Use a small positive value if necessary
% Check for convergence
if abs(f_next – f_guess) < tolerance
f = f_next;
break;
end
f_guess = f_next;
f_convergence(i) = f_guess;
end
% Iterative solution for the diameter of the pipe using the Darcy-Weisbach equation
D_guess = 1;
D_convergence = zeros(1, maxIterations);
for i = 1:maxIterations
D_next = ((4 * f * L * Q^2) / (pi^2 * g * D_guess^5) + h_loss)^(1/5);
% Ensure that the diameter is positive
D_next = max(D_next, 1e-6); % Use a small positive value if necessary
% Check for convergence
if abs(D_next – D_guess) < tolerance
D = D_next;
break;
end
D_guess = D_next;
D_convergence(i) = D_guess;
end
This is not all of the code but this is where I am certain the error is occuring, my professors calculated result is 1.33 ft, however on I am getting an astoundingly large number of 2.36. I was wondering if there is any obvious mistakes I made in the iteration that are resulting in this.
The variables are:
Given data
Q = 4000; % Volumetric flow rate in gpm
L = 10000; % Length of the pipe in ft
h_loss = 75; % Head loss in ft
epsilon = 0.00015; % Roughness of the pipe in ft
g = 32.2; % Acceleration due to gravity in ft/s^2
mu = 0.00001; % Dynamic viscosity in ft^2/s The code for a project I am doing looks like this:
% Convert flow rate to cubic feet per second
Q = Q / 448.831;
% Initial guess for Darcy friction factor f
f_guess = 0.02;
% Iterative solution for f using the Colebrook equation
maxIterations = 100000;
tolerance = 1e-6;
f_convergence = zeros(1, maxIterations);
for i = 1:maxIterations
f_next = 1 / (2 * log10(abs((epsilon/12) / (3.7) + (2.51 / (Re(Q, f_guess, mu))) / sqrt(f_guess))));
% Ensure that the friction factor is positive
f_next = max(f_next, 1e-6); % Use a small positive value if necessary
% Check for convergence
if abs(f_next – f_guess) < tolerance
f = f_next;
break;
end
f_guess = f_next;
f_convergence(i) = f_guess;
end
% Iterative solution for the diameter of the pipe using the Darcy-Weisbach equation
D_guess = 1;
D_convergence = zeros(1, maxIterations);
for i = 1:maxIterations
D_next = ((4 * f * L * Q^2) / (pi^2 * g * D_guess^5) + h_loss)^(1/5);
% Ensure that the diameter is positive
D_next = max(D_next, 1e-6); % Use a small positive value if necessary
% Check for convergence
if abs(D_next – D_guess) < tolerance
D = D_next;
break;
end
D_guess = D_next;
D_convergence(i) = D_guess;
end
This is not all of the code but this is where I am certain the error is occuring, my professors calculated result is 1.33 ft, however on I am getting an astoundingly large number of 2.36. I was wondering if there is any obvious mistakes I made in the iteration that are resulting in this.
The variables are:
Given data
Q = 4000; % Volumetric flow rate in gpm
L = 10000; % Length of the pipe in ft
h_loss = 75; % Head loss in ft
epsilon = 0.00015; % Roughness of the pipe in ft
g = 32.2; % Acceleration due to gravity in ft/s^2
mu = 0.00001; % Dynamic viscosity in ft^2/s newtons method MATLAB Answers — New Questions