0% found this document useful (0 votes)
11 views

Hyperbolics

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Hyperbolics

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

clc;

clear all;
while(1)
fprintf("Processes available:\n")
fprintf("1:FTBS Upwind Explicit scheme:\n")
fprintf("2:Lax Explicit scheme:\n")
fprintf("3:CTCS-Midpoint leap frog scheme:\n")
fprintf("4:Lax-wendroff scheme:\n")
fprintf("5:BTCS Implicit scheme:\n")
fprintf("6:BTBS Implicit scheme:\n")
fprintf("7:Crank-Nicolson semi-explicit multistep scheme:\n")
fprintf("8:Richit-Meyer scheme:\n")
fprintf("9:Lax-wendroff multistep scheme:\n")
fprintf("10:Maccormack scheme:\n")
fprintf("11:Flux collector scheme:\n")
fprintf("exit for any other number\n")
z=input('specify the process number:');
switch(z)
case 1
disp("FTBS Upwind Explicit Scheme")
case 2
disp("Lax Explicit scheme")
case 3
disp("CTCS-Midpoint leap frog scheme")
case 4
disp("Lax-wendroff scheme")
case 5
disp("BTCS Implict Scheme")
case 6
disp("BTBS Implicit scheme")
case 7
disp("Crank-Nicolson semi-explicit multistep scheme")
case 8
disp("Richit-Meyer scheme")
case 9
disp("Lax-wendroff multistep scheme")
case 10
disp("Maccormack scheme")
case 11
disp("Flux collector scheme")
otherwise
disp("invalid number")
return;
end
a=250;
x=0:5:400;
length=400;
dx=5;
nx=(length/dx)+1;
c=input("Enter the courant number:");

1
dt=c*dx/a;
time=0.5;
n=time/dt;
i=0;
for i=1:nx
if x(i)<=50
u(i)=0;
else if x(i)<=110
u(i)=100*sin(pi*(x(i)-50)/60);
else
u(i)=0;
end
end
end
un=u;
uold=u;
plot(x,un);
hold on;
for iterations=1:n % n is the no of time steps
switch(z)
case 1
for i=2:nx-1
un(i)=u(i)-c*(u(i)-u(i-1));
end
case 2
for i=2:nx-1
un(i)=0.5*(u(i+1)+u(i-1)-0.5*c*(u(i+1)-u(i-1)));
end
case 3
if(iterations==1)
u(2:nx-1)=uold(2:nx-1)-c*(uold(2:nx-1)-uold(1:nx-2));
else
un(2:nx-1)=uold(2:nx-1)-0.5*c*(u(3:nx)-u(1:nx-2));
uold=u;
u=un;
end
case 4

un(i)=u(i)-0.5*c*(u(i+1)-u(i-1))
+0.5*c*c(u(i-1)-2*u(i)+u(i+1));

case 5
e(1:nx-3)=c/2;
f(1:nx-2)=-1;
g(1:nx-3)=-c/2;
r(1:nx-2)=-u(2:nx-1);
r(1)=r(1)-c*0.5*u(1);
r(nx-2)=r(nx-2)+c*0.5*u(nx);
un(2:nx-1)=tridiagonal(e,f,g,r);
case 6

2
un(2:nx-1)=(u(2:nx-1)+c*u(1:nx-2))/(1+c);
case 7
e(1:nx-3)=c/4;
f(1:nx-2)=-1;
g(1:nx-3)=-c/4;
r(1:nx-2)=-u(2:nx-1)+0.25*c*(u(3:nx)-u(1:nx-2));
r(1)=r(1)-c*0.25*u(1);
r(nx-2)=r(nx-2)+c*0.25*u(nx);
un(2:nx-1)=tridiagonal(e,f,g,r);
case 8
u(2:nx-1)=0.5*(uold(3:nx)+
(uold(1:nx-2)))-0.25*c*(uold(3:nx)-(uold(1:nx-2)));
un(2:nx-1)=uold(2:nx-1)-0.5*c*(u(3:nx)-(u(1:nx-2)));
uold=u;
u=un;
case 9
u(2:nx-1)=0.5*(uold(3:nx)
+uold(2:nx-1))-0.5*c*(uold(3:nx)-uold(2:nx-1));
un(2:nx-1)=uold(2:nx-1)-c*(u(2:nx-1)-u(1:nx-2));
uold=u;
u=un;
case 10

u(2:nx-1)=uold(2:nx-1)-c*(uold(2:nx-1)-uold(1:nx-2));
un(2:nx-1)=0.5*(uold(2:nx-1)+u(2:nx-1)-0.5*c*(u(2:nx-1)-
u(1:nx-2)));
uold=u;

case 11
eps1=0.026;
for i=2:nx-1
u(i)=uold(i)-0.5*c*(uold(i+1)-uold(i-1))+
(eps1+0.5*c*c)*(uold(i+1)-2*uold(i));
end
eps2=0.002;
for i=2:nx-1
un(i)=u(i)-eps2*(u(i+1)-2*u(i)+u(i-1));
end
uold=u;
otherwise
return;
end
u=un;
if rem(iterations,2)==0
plot(x,un);
end
end
end

Processes available:

3
1:FTBS Upwind Explicit scheme:
2:Lax Explicit scheme:
3:CTCS-Midpoint leap frog scheme:
4:Lax-wendroff scheme:
5:BTCS Implicit scheme:
6:BTBS Implicit scheme:
7:Crank-Nicolson semi-explicit multistep scheme:
8:Richit-Meyer scheme:
9:Lax-wendroff multistep scheme:
10:Maccormack scheme:
11:Flux collector scheme:
exit for any other number
FTBS Upwind Explicit Scheme

Processes available:
1:FTBS Upwind Explicit scheme:
2:Lax Explicit scheme:
3:CTCS-Midpoint leap frog scheme:
4:Lax-wendroff scheme:
5:BTCS Implicit scheme:
6:BTBS Implicit scheme:
7:Crank-Nicolson semi-explicit multistep scheme:
8:Richit-Meyer scheme:
9:Lax-wendroff multistep scheme:
10:Maccormack scheme:
11:Flux collector scheme:
exit for any other number
invalid number

You might also like