I need to code a pipe network and solve for flow rates and ideal pump head. I have the basis of a code using fsolve with my equations and unkowns, but keep exceeding iteration
function Mary_H_Kennedy_Fluids_Project
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pipe Flow Project
% Mary Helen Kennedy
% ME 3834 — Fluid Mechanics
% Spring 2024
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Q1 = 4.456; %ft3/s
v1 = 22.69; %ft/s
L = 100; %ft
D = 0.5; %ft
e = 0.00085; %ft
rho = 62; %lbm/ft^3
f = 0.0023; %Initial guess
mu = 2.05*10^-5;
Re = (rho*v1*D)/mu;
A = 0.196;
% Define the function
fun = @(F) [
(F(2)/(rho*9.81)) – (F(1)) + ((v1^2)/(2*9.81)*(f*(L/D)-1)); % Equation for Pipe 1
F(2) – (rho*9.81)*(f*(L/D)*(F(5)^2)/(2*9.81*A^2)); % Equation for Pipe 2
F(2) – (rho*9.81)*(f*(L/D)*(F(5)^2)/(2*9.81*A^2)); % Equation for Pipe 3
(F(2) – F(4)) – (rho*9.81)*(f*(L/D)*(F(6)^2)/(2*9.81*A^2)); % Equation for Pipe 4
F(4) – (rho*9.81)*(f*(L/D)*(F(7)^2)/(2*9.81*A^2)); % Equation for Pipe 5
F(4) – (rho*9.81)*(f*(L/D)*(F(8)^2)/(2*9.81*A^2)); % Equation for Pipe 6
F(5) + F(5) + F(6) – Q1; % Node A
F(6) – F(7) – F(8); % Node B
];
% Initial guess for unknowns
x0 = [2000, 500, 0.0023, 400, 24, 25, 26, 27];
% Call fsolve to solve the system of equations
options = optimoptions(‘fsolve’,’MaxFunctionEvaluations’,10000); % Adjust the maximum number of function evaluations
% Call fsolve with options
F = fsolve(fun, x0, options);
% Unknowns from fsolve
hl = F(1);
Pa = F(2);
f = F(3);
Pb = F(4);
Q3 = F(5);
Q4 = F(6);
Q5 = F(7);
Q6 = F(8);
endfunction Mary_H_Kennedy_Fluids_Project
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pipe Flow Project
% Mary Helen Kennedy
% ME 3834 — Fluid Mechanics
% Spring 2024
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Q1 = 4.456; %ft3/s
v1 = 22.69; %ft/s
L = 100; %ft
D = 0.5; %ft
e = 0.00085; %ft
rho = 62; %lbm/ft^3
f = 0.0023; %Initial guess
mu = 2.05*10^-5;
Re = (rho*v1*D)/mu;
A = 0.196;
% Define the function
fun = @(F) [
(F(2)/(rho*9.81)) – (F(1)) + ((v1^2)/(2*9.81)*(f*(L/D)-1)); % Equation for Pipe 1
F(2) – (rho*9.81)*(f*(L/D)*(F(5)^2)/(2*9.81*A^2)); % Equation for Pipe 2
F(2) – (rho*9.81)*(f*(L/D)*(F(5)^2)/(2*9.81*A^2)); % Equation for Pipe 3
(F(2) – F(4)) – (rho*9.81)*(f*(L/D)*(F(6)^2)/(2*9.81*A^2)); % Equation for Pipe 4
F(4) – (rho*9.81)*(f*(L/D)*(F(7)^2)/(2*9.81*A^2)); % Equation for Pipe 5
F(4) – (rho*9.81)*(f*(L/D)*(F(8)^2)/(2*9.81*A^2)); % Equation for Pipe 6
F(5) + F(5) + F(6) – Q1; % Node A
F(6) – F(7) – F(8); % Node B
];
% Initial guess for unknowns
x0 = [2000, 500, 0.0023, 400, 24, 25, 26, 27];
% Call fsolve to solve the system of equations
options = optimoptions(‘fsolve’,’MaxFunctionEvaluations’,10000); % Adjust the maximum number of function evaluations
% Call fsolve with options
F = fsolve(fun, x0, options);
% Unknowns from fsolve
hl = F(1);
Pa = F(2);
f = F(3);
Pb = F(4);
Q3 = F(5);
Q4 = F(6);
Q5 = F(7);
Q6 = F(8);
end function Mary_H_Kennedy_Fluids_Project
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Pipe Flow Project
% Mary Helen Kennedy
% ME 3834 — Fluid Mechanics
% Spring 2024
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Q1 = 4.456; %ft3/s
v1 = 22.69; %ft/s
L = 100; %ft
D = 0.5; %ft
e = 0.00085; %ft
rho = 62; %lbm/ft^3
f = 0.0023; %Initial guess
mu = 2.05*10^-5;
Re = (rho*v1*D)/mu;
A = 0.196;
% Define the function
fun = @(F) [
(F(2)/(rho*9.81)) – (F(1)) + ((v1^2)/(2*9.81)*(f*(L/D)-1)); % Equation for Pipe 1
F(2) – (rho*9.81)*(f*(L/D)*(F(5)^2)/(2*9.81*A^2)); % Equation for Pipe 2
F(2) – (rho*9.81)*(f*(L/D)*(F(5)^2)/(2*9.81*A^2)); % Equation for Pipe 3
(F(2) – F(4)) – (rho*9.81)*(f*(L/D)*(F(6)^2)/(2*9.81*A^2)); % Equation for Pipe 4
F(4) – (rho*9.81)*(f*(L/D)*(F(7)^2)/(2*9.81*A^2)); % Equation for Pipe 5
F(4) – (rho*9.81)*(f*(L/D)*(F(8)^2)/(2*9.81*A^2)); % Equation for Pipe 6
F(5) + F(5) + F(6) – Q1; % Node A
F(6) – F(7) – F(8); % Node B
];
% Initial guess for unknowns
x0 = [2000, 500, 0.0023, 400, 24, 25, 26, 27];
% Call fsolve to solve the system of equations
options = optimoptions(‘fsolve’,’MaxFunctionEvaluations’,10000); % Adjust the maximum number of function evaluations
% Call fsolve with options
F = fsolve(fun, x0, options);
% Unknowns from fsolve
hl = F(1);
Pa = F(2);
f = F(3);
Pb = F(4);
Q3 = F(5);
Q4 = F(6);
Q5 = F(7);
Q6 = F(8);
end fsolve, fluids, help, iterations MATLAB Answers — New Questions