Trying to create a Haaland function to find friction factor inside a loop.
4 views (last 30 days)
Show older comments
Hello everybody,
I'm trying to find the friction factor to calculate major head loss for 3 different given flow rates for water. I'm a beginner in MATLAB so I couldn't create a function inside my for loop that would calculate 3 different friction factors using Haalands Equation (or Colebrook).
So far the code looks like;
clc; clear all;
% Constants
g = 9.81; % Gravitational acceleration (m/s^2)
rho = 998.23; % Density of water at 20°C (kg/m^3)
D = 25/1000; % Diameter of Galvanized pipe (m)
mu = 1.0016/1000; % Dynamic viscosity of water at 20°C (Pa*s)
K = 0.10; % Minor loss coefficient
epsilon = 0.15; % Roughness coefficient for Galvanized pipe
L = 1.04; % Pipe length (m)
eD = epsilon/D;
Ac = pi*((D^2)/4); % Cross-section area
Vdot = (1000:500:2000)/3600000; % Flow rates (m^3/s)
% Calculations
for i = Vdot
V = Vdot/Ac;
Re = ((rho*V*D)/mu);
f = ???;
hLminor = K*((V.^2)/(2*g));
hLmajor = f*(L/D)*((V^2)/(2*g));
hLtotal = hLmajor + hLminor;
end
I have found several examples of Haaland or Colebrook online for matlab but they use "function" which doesn't work in my loop. Any help would be appreciated.
0 Comments
Answers (1)
Cris LaPierre
on 1 Apr 2021
Functions can be used anywhere in your code, but they must be defined at the bottom of your script. See this page for more details and examples.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!