4
MATLAB Codes for Hyperbolic PDE Using FTBS Explicit Scheme: clear all; a=250; % Take Spatial step size=10 d=10; % Take number of time levels=50 n=1:1:51; % Take temporal time step=0.02 such that Courant number,c<=1 % c<=1 for stable FTBS explicit scheme t=0.02; c=(a*t)/d; x=0:10:400; i=41; u= zeros(i,n); % loop to get the velocity at initial time level for(n=1) for i=1:1:6 u(i,n)=0; end for i=6:1:12 u(i,n)=(100*sin(3.14*((x(i)-50)/60))); end for i=13:1:41 u(i,n)=0; end end % loop imposing boundary conditions at the end grid points for different time levels for n=1:1:51 u(1,n)=0; u(41,n)=0; end % loop to get velocity values at all the grid points(except at end points) for different time levels for n=2:1:50 for i=2:1:40 % FTBS Explicit scheme u(i,n)=(1-c)*u(i,n-1)+(c)*u(i-1,n-1); end end figure(); % plotting a 3d figure surf(u'); title('Plot showing u vs i at different time levels using FTBS Explicit Scheme for C=0.5', 'FontSize', 18); xlabel('Grid Points (i)', 'FontSize', 14); ylabel('Time Level (t)', 'FontSize', 14); zlabel('Velocity (u)', 'FontSize', 14);

MATLAB Codes for Hyperbolic PDE

Embed Size (px)

DESCRIPTION

q

Citation preview

Page 1: MATLAB Codes for Hyperbolic PDE

MATLAB Codes for Hyperbolic PDE

Using FTBS Explicit Scheme:

clear all; a=250; % Take Spatial step size=10 d=10; % Take number of time levels=50 n=1:1:51; % Take temporal time step=0.02 such that Courant number,c<=1 % c<=1 for stable FTBS explicit scheme t=0.02; c=(a*t)/d; x=0:10:400; i=41; u= zeros(i,n); % loop to get the velocity at initial time level for(n=1) for i=1:1:6 u(i,n)=0; end for i=6:1:12 u(i,n)=(100*sin(3.14*((x(i)-50)/60))); end for i=13:1:41 u(i,n)=0; end end % loop imposing boundary conditions at the end grid points for different time

levels for n=1:1:51 u(1,n)=0; u(41,n)=0; end % loop to get velocity values at all the grid points(except at end points)

for different time levels for n=2:1:50 for i=2:1:40 % FTBS Explicit scheme u(i,n)=(1-c)*u(i,n-1)+(c)*u(i-1,n-1); end end figure(); % plotting a 3d figure surf(u'); title('Plot showing u vs i at different time levels using FTBS Explicit

Scheme for C=0.5', 'FontSize', 18); xlabel('Grid Points (i)', 'FontSize', 14); ylabel('Time Level (t)', 'FontSize', 14); zlabel('Velocity (u)', 'FontSize', 14);

Page 2: MATLAB Codes for Hyperbolic PDE

Plots Showing BlowUp and Convergence using FTBS Explicit

Scheme:

a) Blow Up case for t=0.041

b) Convergence case for t=0.02

Page 3: MATLAB Codes for Hyperbolic PDE

Using Lax Wendroff Scheme:

clear all; a=250; % Take Spatial step size=10 d=10; % Take number of time levels=50 n=1:1:51; % Take temporal time step=0.02 such that Courant number,c<=1 % c<=1 for stable Lax Wendroff scheme t=0.02; c=(a*t)/d; x=0:10:400; i=41; u= zeros(i,n); % loop to get the velocity at initial time level for(n=1) for i=1:1:6 u(i,n) = 0; end for i=6:1:12 u(i,n)=(100*sin(3.14*((x(i)-50)/60))); end for i=13:1:41 u(i,n)=0; end end % loop imposing boundary conditions at the end grid points for different time

levels for n=1:1:51 u(1,n)=0; u(41,n)=0; end % loop to get velocity values at all the grid points(except at end points)for

different time levels for n=2:1:50 for i=2:1:40 % Lax Wendroff scheme u(i,n)=u(i+1,n-1)*((c^2-c)/2)+u(i,n-1)*(1-c^2)+u(i-1,n-

1)*((c^2+c)/2); end end figure(); % plotting a 3d figure surf(u'); title('Plot showing u vs i at different time levels using Lax Wendroff Scheme

for C=0.5', 'FontSize', 18); xlabel('Grid Points (i)', 'FontSize', 14); ylabel('Time Level (t)', 'FontSize', 14); zlabel('Velocity (u)', 'FontSize', 14);

Page 4: MATLAB Codes for Hyperbolic PDE

Plots Showing BlowUp and Convergence using Lax Wendroff

Scheme:

a) Blow Up case for t=0.041

b) Convergence case for t=0.02