Finite difference method Boundary conditions

1 次查看(过去 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 个)

类别

Help CenterFile Exchange 中查找有关 Signal Generation and Preprocessing 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by