Skip to content

Instantly share code, notes, and snippets.

@NassimBentarka
Last active October 18, 2018 21:08
Show Gist options
  • Save NassimBentarka/76276b2320da959828cd07994d5d4542 to your computer and use it in GitHub Desktop.
Save NassimBentarka/76276b2320da959828cd07994d5d4542 to your computer and use it in GitHub Desktop.
Ce script MATLAB permet le calcul du coefficient de friction (Lambda) F selon la corrélation de Colebrook. // A Matlab script to compute the friction coefficient based on Colebrook correlation.
%Auteur: Nassim BENTARKA
%Ecrit le 15/05/2018
%INPUT:
%Nombre de Reynolds: R ; et Rugosité relative: K
%Le nombre d'itérations
%OUTPUT:
%Coefficient de friction lambda: F
function F=colebrook(R,K)
%Test d'erreurs d'entree:
if any(R(:)<=0)==1
error('Le nombre de Reynolds doit etre positif (R>2000).');
end
if nargin==1
K=0;
end
if any(K(:)<0)==1
error('La rugosité relative doit etre positive.');
end
%Initialisation des variables
X1=(log(10).*K.*R)/(2*3.7*2.51);
X2=log((log(10).*R)./(2*2.51));
iterations=2;
%Premier terme: Z0=X2-1/5
F=X2-0.2;
%Evaluation des j-termes
for i=1:1:iterations
E=(log(X1+F)+F-X2)./(1+X1+F); %Epsilon
F=F-(1+X1+F+0.5*E).*E.*(X1+F)./(1+X1+F+E.*(1+E/3));
end
%Solution finale
F=((log(10)/2)./F).^2;
F
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment