You are on page 1of 3

%AERSP 312 Computer Project 1

%y''' + y*y'' + B[1 - y'*y'] = 0 ODE


%y = y ; y' = dy/dn = z ; y'' = dz/dn = a ; da/dn = [Function(n,y,z,a)] = y''' = B*[z*z - 1] -
y*a
%Start at n = 0
%Initial conditions y(0) = 0 ; z(0) = 1 ; a(0) = guess

format longE;
clear
clc %Clears MATLAB Window

a = 0;
b = 10; %Determines interval from a <= n <= b;

h = .05; %Step size


N = ((b-a)/h); %Number of steps

n(1) = 0; %Declares initial n (eta) at 0


y(1) = 0; %Boundary Condition G(0) = 0
z(1) = 0; %Boundary Condition dG/dn(0) = 0
aBCs = [.02474781 .4696548 .9278041 1.232748 1.400359]; %Boundary Condition G''(0) = [Guess] ;
Compare to G' = 1 for accuracy
B = [-0.198 0.000 0.500 1.000 1.333]; %Defines arrary for freestream pressure gradient

j = 1;
while j <= length(B);
BGen = B(j); %Sets generic B values for current array index and overwrites for each
iteration
y = y(1); %Sets original initial conditions for y, z and a
z = z(1);
a = aBCs(j); %Sets a to guesses in y'' boundary conditions arrary

Fxyza = @(n,y,z,a) z; %dy/dn = z A.K.A G'


Gxyza = @(n,y,z,a) a; %dz/dn = a A.K.A G''
Hxyza = @(n,y,z,a) BGen*(z*z - 1) - y*a; %da/dn = [function(n,y,z,a)] A.K.A G'''

i = 1; %Loop control variable;


while i <= N; %Runs for the interval from a to b

%Runge-Kutta 4th order algorithm based off


%k0, k1, k2 and k3 to estimate next y, z and a values

k0(i) = h*Fxyza(n(i),y(i),z(i),a(i)); %Declares arrary for k0 values


L0(i) = h*Gxyza(n(i),y(i),z(i),a(i)); %Declares arrary for L0 values
M0(i) = h*Hxyza(n(i),y(i),z(i),a(i)); %Declares arrary for M0 values

k1(i) = h*Fxyza(n(i) + .5*h, y(i) + .5*k0(i), z(i) + .5*L0(i), a(i) + .5*M0(i));


%Determines arrary for k1 values
L1(i) = h*Gxyza(n(i) + .5*h, y(i) + .5*k0(i), z(i) + .5*L0(i), a(i) + .5*M0(i));
%Determines arrary for L1 values
M1(i) = h*Hxyza(n(i) + .5*h, y(i) + .5*k0(i), z(i) + .5*L0(i), a(i) + .5*M0(i));
%Determines arrary for M1 values
k2(i) = h*Fxyza(n(i) + .5*h, y(i) + .5*k1(i), z(i) + .5*L1(i), a(i) + .5*M1(i));
%Determines arrary for k2 values
L2(i) = h*Gxyza(n(i) + .5*h, y(i) + .5*k1(i), z(i) + .5*L1(i), a(i) + .5*M1(i));
%Determines arrary for L2 values
M2(i) = h*Hxyza(n(i) + .5*h, y(i) + .5*k1(i), z(i) + .5*L1(i), a(i) + .5*M1(i));
%Determines arrary for M2 values

k3(i) = h*Fxyza(n(i) + h, y(i) + k2(i), z(i) + L2(i), a(i) + M2(i)); %Determines arrary
for k3 values
L3(i) = h*Gxyza(n(i) + h, y(i) + k2(i), z(i) + L2(i), a(i) + M2(i)); %Determines arrary
for L3 values
M3(i) = h*Hxyza(n(i) + h, y(i) + k2(i), z(i) + L2(i), a(i) + M2(i)); %Determines arrary
for M3 values

y(i+1) = y(i) + (1/6)*(k0(i) + 2*k1(i) + 2*k2(i) + k3(i)); %Using Rk4 Algorithm to


estimate y at next step
z(i+1) = z(i) + (1/6)*(L0(i) + 2*L1(i) + 2*L2(i) + L3(i)); %Using Rk4 Algorithm to
estimate z at next step
a(i+1) = a(i) + (1/6)*(M0(i) + 2*M1(i) + 2*M2(i) + M3(i)); %Using Rk4 Algorithm to
estimate a at next step

n(i+1) = n(i) + h; %Increments to the next step size

%End of Runge-Kutta algorithm

i = i+1; %Adds one to the loop control variable

end

%Graph of the boundary-layer velocity profiles


%for the different values of B (Beta)
figure(1)
hold on;
grid on;
if j == 1; %Sets different line colors on one graph for the five beta values
plot(z,n,'k');
elseif j == 2;
plot(z,n,'r');
elseif j == 3;
plot(z,n,'b');
elseif j == 4;
plot(z,n,'g');
else j == 5;
plot(z,n,'c');
legend('B = -0.198','B = 0.000','B = 0.500','B = 1.000','B = 1.333','Location','Best')
end
axis([0 1 0 5]);
title(['Boundary-Layer Velocity Profile with a step size of ' num2str(h)]);
xlabel('Velocity (dG/dn)');
ylabel('Eta (n)');
j = j+1; %Increments Beta(j) to next array value and runs till end of Beta array
end

You might also like