clear all
clc
eta = 10;
dt = 0.01;
N = eta/dt + 1;
t = linspace(0,eta, N);
K = 1001;
tol = 1e-5;
fid1 = fopen('blasius_eta_data.txt', 'wt');
fid2 = fopen('blasius_f_data.txt', 'wt');
fid3 = fopen('blasius_g_data.txt', 'wt');
fid4 = fopen('blasius_h_data.txt', 'wt');
fid5 = fopen('guessdata.txt', 'at');
f = zeros(N,K);
g = zeros(N,K);
h = zeros(N,K);
f(1,:) = 0;
g(1,:) = 0;
h(1,1) = 5;
h(1,2) = 7;
for k = 1:K-1
for i = 2:N
f(i,k) = f(i-1, k) + g(i-1, k)*dt;
g(i,k) = g(i-1, k) + h(i-1, k)*dt;
h(i,k) = h(i-1, k) - (f(i-1, k)*h(i-1, k)*dt)/2;
end
% if tolerance is met, iter = k and break out of the loop
if abs(g(N,k) - 1) < tol
iter = k
break
end
% want to skip this case
if k == 1
continue;
else
% applying shooting method to determine the next guess
h(1, k+1) = h(1,k) + (1 - g(N,k))*(h(1,k) - h(1, k-1))/(g(N, k) - g(N, k-1));
% condition on h(1,:) - cannot be a negative value
if sign(h(1, (k+1))) == 1
h(1, k+1) = -h(1, k+1);
end
end
end
%transporting for data collection purposes
t_col = transpose(t);
fprintf(fid1, '%.5f\n', t_col);
fprintf(fid1, '%.5f\n', f(:, iter));
fprintf(fid1, '%.5f\n', g(:, iter));
fprintf(fid1, '%.5f\n', h(:, iter));
fprintf(fid1, '%.5f %.5f\n', [dt; h(1, iter)]);
%
% plotting
plot(f(:, iter), t);
hold on
plot(g(:, iter), t);
plot(h(:, iter), t);