Finite difference method Boundary conditions
3 次查看(过去 30 天)
显示 更早的评论
How to set the boundary conditions and initial conditions for the problem mentioned below?. I tried the below mentioned code. But it seems it's not correct.
% Simulation of a 1-D Linear Convection model by a time march (Finite
...Difference Method)
% Numerical scheme used is a first order upwind in both space and time
%%
clc;
clear;
%Specifying Parameters
xr=1; % Space(x) right side limit
xl=0; % Space(x) left side limit
dx=0.05;%Width of space step
x=xl:dx:xr;%Range of x (0,1) and specifying the grid points
nx=length(x);%Number of steps in space(x)
tr=20; % time(t) right side limit
tl=0; % time(t) left side limit
dt=0.04;%Width of each time step
t=tl:dt:tr;
nt=length(t);
a=1.0;
for i=1:nx
u(i,1)=(sin(pi*x(i)))^40;%%%Initial conditions
end
for x=1:nx-1
for t=1:nt-1
u(x,t+1)=u(x,t)+(dt/dx)*(u(x+1,t)-u(x,t));
u(end,t)=u(1,t);%%%Boundary conditions
end
end
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!