Professional Documents
Culture Documents
a)
i) To find the constants c1 and c2 that best fit the model (1) to the experimental data, we
can formulate the residual in the form r = Ax - b, where x represents the vector [c1; c2].
In this special case with n = 4 data points, we can define the elements of matrix A and
column vector b as follows:
Matrix A:
The second column of A contains ln(Rej * sqrt(λj)) for each data point.
Column Vector b:
Each element of the column vector b corresponds to a data point and is calculated as 1 / sqrt(λj).
Now, we can express the residual as a linear combination of the coefficients c1 and c2:
The residual vector r, the coefficient vector x, matrix A, and vector b can be defined as follows:
Residual Vector r:
r = [r1; r2; r3; r4], where each rj is given by the formula above.
Coefficient Vector x:
x = [c1; c2]
Matrix A:
Column Vector b:
ii)
% Date: 31/10/2023
% Input:
% Output:
if length(Re) ~= length(lam)
end
n = length(Re);
b = 1 ./ sqrt(lam);
c = A \ b;
end
b)
% Extract coefficients
c1 = c(1);
c2 = c(2);
function df = derivative(f, x)
% Calculate the derivative of function f at point x using a small
perturbation
h = 1e-6; % Small perturbation
df = (f(x + h) - f(x)) / h;
end
c)
% Calculate the friction factor using evalFriction for each Reynolds number
for i = 1:length(Re)
lamCalculated(i) = evalFriction(Re(i), c);
end
d)