Project

Linear Convection

The wave equation is given by the formula ``du/dt + c*du/dx=0``. The domain length is 1m along which the grid is created with the help of finite difference scheme. Initilal velocity profile is step function between x=0.3 and x=0.5. A matlab code s written inorder to determine the final velocity of the differential equation. forward scheme is applied to the time derivation and backward derivative to the x derivative as mentioned in the challenge. The time step is used as 0.01 inorder to check the stability of the solution with different grid sizes.

The matlab code for the following is shown below:

clear all 
close all
clc 

L=1;
n=[20 40 100 160];
y=1:length(n);
c=1;
dt=1e-2;

for j=1:length(y)
x=0:(L/(n(j)-1)):L;
%dx=L/(n-1)
xstart=0.3;
[val,idx]=min(abs(x-xstart));
k=x(idx);
xend=0.5;
[val,idx]=min(abs(x-xend));
k1=x(idx);
dx=x(2)-x(1);
K=find(x==k);
K1=find(x==k1);
%start and end of square wave profile 
n_start=K;
n_stop =K1;

u=1*ones(1,n(j));
u(n_start:n_stop)=2;

u(1)=1;
u_old=u;
u_initial=u;

t=0.4
nt=t/dt
% time marching loop 
for k=1:nt

    % space loop 
for i=2:n(j)
    u(i) =u_old(i)-(c*dt/dx)*(u_old(i)-u_old(i-1));
      
end 
figure(j)
plot(x,u_initial,'b')
hold on
plot(x,u,'r')
grid on 
axis([0.1 1.2 0.5 2.1])
pause(0.00005)
u_old =u;
end

 
end 


The velocity profile as shown in the figure for four different grids shows that that the velocity profile keeps getting better with increase in grid points till it is 80 and it blows up at grid size 160. The velocity profile with less grid points 20 and 40 have velocity profiles getting steeper with increase in time. it was tested with various grid points at which point does the solution get unstable. It was seen that with grid points 101 the solution doesnt remain consistent anymore. So making the grid point finer isnt going to make the solution accurate or more stable.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.