You are on page 1of 3

Question 3

(ii)
% Part (b) (ii) of Question 3

% Definition of the variables


h = 0.2; % Step size
a = 0; % minimum value of z
b = 10; % maximum value of z

y0 = [0 ; 0; 0.332]; % initial conditions of the equation

% Initialization of the variables


y(: ,1) = y0; % Initial value of y
z(1) = a; % Initial value of z
N = (b - a)/h; % Calculates the number of panels

% This section presents the RK algorithm which iteratively calculates the


values
% of y, U and U'. The next value of y (or y(n+1)) is computed from the sum of
its...
% current value and the weighted average of two increments defined as k1 and
k2 where:...
% k1 is the increment according to the slope at the interval(i) The next
value of y (or y(n+1))...
% is computed from the sum of its current value and the weighted average of
two increments...
% defined as k1 and k2 where: k1 is the increment according to the slope at
the interval's start...
% while k2 is the increment according to the slope at the interval's midpoint
s start while ...
% k2 is the increment according to the slope at the interval's midpoint

for n = 1 : N
k1 (1) = h*y(2,n);
k1 (2) = h*y(3,n);
k1 (3) = h * -0.5*y(1,n)*y(3,n);
k2 (1) = h*(y(2,n) + k1 (2));
k2 (2) = h*(y(3,n) + k1 (3));
k2 (3) = h * -0.5*( y(1,n) + k1 (1))*(y(3,n) + k1 (3));
y(:,n+1) = y(:,n) + 0.5*( k1' + k2');
z(n+1) = z(n) + h;
end
(iii)
% Part (b) (iii) of Question 3
% Output of the IVP solution
for n = 1 : N + 1
f(n) = y(1,n); % values of y for every z-instance
U_p(n) = y(2,n); % values of velocity profile, U for every z-
instance
U_g(n) = y(3,n); % values of velocity gradient, U' for every z-
instance
fprintf('%10.4 f | %10.4 f | %10.4 f | %10.4 f\n',z(n),y(1,n),y(2,n),y(3,n))
end

% Plot of velocity profile versus z


plot (z, U_p);
xlabel ('z');
ylabel ('Velocity Profile, U');
title('Velocity profile versus z')
% Plot of velocity gradient versus z
plot (z, U_g);
xlabel ('z');
ylabel ('Velocity gradient');
title('Velocity gradient versus z')

(iv)
The velocity profile U(z) semi-linearly increases with z till a maximum unity velocity achieved.
Thereafter, the velocity remains constant despite the increasing values of z and so the graph flattens
off.
The velocity gradient profile depicts a decreasing behaviour with the increasing values of z. For the
regions in which the velocity profile is constant, the velocity gradient is zero.
(v)
As seen in the graphical profile of velocity U(z) against z, as z approaches 10 i.e. beyond z = 6, U(z)
flattens off to unity. Similary, for the velocity gradient profile, U’(z) approaches zero as z tend
towards 10. This conforms to the mathematical behaviour of derivatives of constants (which is always
a zero) i.e.
dU
U' (z )=
dz
d
If U ( z ) → 1, then (1 )=0
dz

So ,U ' ( z ) → 0 for z →1 0
Thus the velocity gradient profile tends to zero as mathematically expected.

You might also like