-
Notifications
You must be signed in to change notification settings - Fork 200
/
Copy pathFD_ThetaScheme_ParabEqu.m
50 lines (37 loc) · 1.1 KB
/
FD_ThetaScheme_ParabEqu.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
%%% Finite Differences Theta Scheme for Parabolic Equation
T=2; %% final time
xmin=-10; xmax=10; %% spatial interval
L=xmax-xmin;
Nx=100; %% number of spatial discretization intervals
h=L/Nx;
x=xmin:h:xmax;
lambda=0.60;
theta=0.1;
dT=lambda*h^2
Nt=floor(T/dT);
u=zeros(Nx+1,1); %% initialization
%u(abs(x)<1)=1; %% Initial condition N1
u(abs(x-1)<=1)=1; %% initial condition N2
u(abs(x+1)<1)=.5; %% initial condition N2
figure(1); plot(x,u); axis([-10 10 -1 1]); drawnow;
pause(1)
%%%% Construction of matrices A and B
D=zeros(Nx-1,1);
D(1)=1-2*(1-theta)*lambda;
D(2)=(1-theta)*lambda;
A=toeplitz(D);
D(1)=1+2*theta*lambda;
D(2)=-theta*lambda;
B=toeplitz(D);
for i=1:Nt
u(2:Nx)=B\(A*u(2:Nx));
figure(1); plot(x,u); axis([-10 10 -1 1]); drawnow;
end;
%%% Possible data
% T=2; Nx=100; lambda=.30; init cond N1
% T=2; Nx=100; lambda=.49; init cond N1
% T=2; Nx=100; lambda=.50; init cond N1
% T=2; Nx=100; lambda=.51; init cond N1
% T=2; Nx=100; lambda=.30; init cond N2
% T=2; Nx=100; lambda=.50; init cond N2
% T=2; Nx=100; lambda=.51; init cond N2