-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssignment 1
More file actions
38 lines (37 loc) · 1.37 KB
/
Assignment 1
File metadata and controls
38 lines (37 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
ed = 10^-4; %given relative roughness value, epsilon/d
c = 0;
r = 0;%for storing Re array from 10^4-10^7
i = 1;%iteration variable declaration
while r < 10^7 %Loop exit condition
Re(i) = 10^4 + c; %Reynold's number array
y(i) = NR(Re(i),ed); %Array for storing the friction factor value
obtained from the NR() function
c = c + 100000; %for creating intervals between 10^4-10^7
r = Re(i); %Storing the reynold's number from each loop
i = i+1; %iteration
end
loglog(Re,y) %to obtain loglog plot of friction factor vs Re
xlabel('Reynolds number')
ylabel('friction factor')
title('log(f) vs log(Re)')
function xold = NR(Re, ed) %function declaration, the function returns
xold=frictionfactor
x0 = 0.01; %initial guess, for other initial guess fail at higher order of
Reynold's number
maxIter = 100; %iteration required for convergence
x = x0;
xold = x0;
for i = 1 : maxIter %iteration start
f = x^-(1/2) + 0.86*log((ed / 3.7)+(2.51/Re)*(x^-(1/2))); %function
declaration, colebrook equation
df1 = (x^(1/2)*((-0.5*ed*Re)-3.99341)-
4.6435)/((ed*Re*(x^2))+(9.287*(x^(3/2)))); %derivative of the function f
x = x - f/df1; %Newton Raphson solver
err = abs (x-xold); %Calculate the difference between the x(i) and x(i+1)
xold = x; %to store the x(i+1) value for the next iteration
if( err<eps) %tolerance limit, if the differnce between x(i) and x(i+1) <
machine epsilon, the loop will end
break;
end
end
end