Linear Convection
⇒The program for comparing the original and final velocity profile for n=20,40,80,160 is shown below
clear all
close all
clc
L=1;
%Source code for n=20,40,80,160 is same just change the value for n
% Here the program is written for n=20
n=20;
x=linspace(0,L,n);
c=1;
dx=x(2)-x(1);
dt=0.01; %Time Step
% u is velocity
u=1*ones(1,n);
%x_start is when step starts
%x_finish is when step ends
x_start=round((0.1/dx) +1)
x_finish=round((0.3/dx) +1)
u(x_start:x_finish)=2;
uold= u;
u_initial=u; % Initial velocity profile
nt=0.4;
% Time Marching solution
for k=1:(nt/dt)
for i= 2:n
u(i)= uold(i) -((c*dx)/dt)*(uold(i)-uold(i-1));
end
uold=u;
end
plot(x,u_initial)
hold on
plot(x,u,\'r\')
xlabel(\'x-axis\')
ylabel(\'Velocity\')
legend(\'Initial velocity profile\',\'Final velocity profile\')
The four plots comparing the original and final velocity profile are shown
⇒Plot for n=20
⇒Plot for n=40
⇒Plot for n=80
⇒Plot for n=160
In the first plot n=20 range of velocity is very high , it reaches to 2e+37 m/s and highly unstable and as the value of n increases its stability incraeses and velocity decreases as you can see for n=160 the highest velocity is 2m/s which is the least compared to other profiles.