Project

Numerical solution to the 1D linear wave equation-Effect of time step size on the solution

OBJECTIVE-

1. To write a code to solve the 1D linear wave equation equation numerically.

Write a function that accepts time step as an argument and solves the same problem. You will compare the effect of time step on the numerical solution.

1. Set n = 80

2. Time steps to use = 1e-4, 1e-3, 1e-2, and 1e-1

3. In a single graph compare the numerical solution at t = 0.4 seconds

4. Plot the simulation time as a function of the time step

1D linear wave equation

`(delu)/(delt)+c*(delu)/(delx)=0`

Discretizing the equation by using forward differencing scheme(FDS) for time derivative and backward differencing scheme(BDS) for space term we get,

`(u_i^(n+1)-u_i^n)/(Deltat)=-C*(u_i^n-u_(i-1)^n)/(Deltax)`

Comparing the numerical solution at t = 0.4 second for time steps 1e-4, 1e-3, 1e-2, and 1e-1

From the above graph it can be seen that at 0.4 seconds the velocity profile is different for different time steps.

1. For time step 1e-3 the peak is the highest.

2. For time step 1e-4 and 1e-2 the peak ialmost same.

3. For time step 1e-1 the solution seems to blow off.

Time taken for simulation for each time step

1. So from the above graph we can see that the time taken for simutation is highest for 1e-1 which is the highest time step.This is because the solution blew off.

2. The simulation time is very less for 1e-2,1e-3and 1e-4 time step.

3. so we can conclude that as we decrease the time step the simulation time also decreaeses.

function [u,x]=time_step(dt)
L=1;
n=80;
c=1;

nstart=0;nstop=0;
x=linspace(0,1,n);
      
 dx=x(2)-x(1);
 nstart=(0.1/dx)+1;
  nstop=(0.3/dx)+1; 
% dt=0.01;
t_end=0.4/dt;
u=ones(1,n);

u(nstart:nstop)=2;
u(1)=1;
 uold=u;

 uinitial=u;

for k=1:t_end;
   
for j=2:length(x);
    u(j)=uold(j)-c*(dt/dx)*(uold(j)-uold(j-1));
end
uold=u;
end
end

%Function calling

tic
[u1,x1]=time_step(1e-1)
toc
t1=toc
tic
[u2,x2]=time_step(1e-2)
toc
t2=toc
tic
[u3,x3]=time_step(1e-3)
toc
t3=toc
tic
[u4,x4]=time_step(1e-4)
t4=toc
timeofsimulation=[t1,t2,t3,t4];
bar(timeofsimulation)
 set(gca,'XTicklabel',{'1e-1','1e-2','1e-3','1e-4'})
 ylabel('time of simulation');
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.