-
Notifications
You must be signed in to change notification settings - Fork 0
/
Redi_snapshots_test.m
53 lines (38 loc) · 864 Bytes
/
Redi_snapshots_test.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
51
52
53
function Phi_t = Redi_snapshots_test(parameter)
% Generate snapshot matrix of reaction-diffusion equation
%% Grid coordinates
a = parameter(1); niu = parameter(2);
N=100;
M=40000;
dx=1/N;
dt=1/M;
x=0:dx:1;
t=0:dt:1;
r=a.*dt/dx^2;
%% Initial condition,boundary condition
xl = 0.5 + 0.5*sin(pi*x);
N = length(x)-1;
M = length(t)-1;
Phi = zeros(M+1,N+1);
Phi(1,:) = xl;
Phi(:,1) = 0.5;
Phi(:,end) = 0.5;
%% Difference equation
for j=1:M
for i=2:N
Phi(j+1,i) = Phi(j,i) + r*(Phi(j,i)-Phi(j,i-1))^2 + Phi(j,i)*r*(Phi(j,i+1)+Phi(j,i-1)-2*Phi(j,i)) -dt*niu*(Phi(j,i)-Phi(j,i)^3);
end
end
%% Mapping
% figure
% [x,t]=meshgrid(x,t);
% mesh(x,t,Phi);
% xlabel('x');
% ylabel('t');
% zlabel('\Phi(x,t)');
% title('\Phi(x,t)');
% view(75,50);
%% Snapshot matrix
ind = 200:200:M+1;
Phi_t = Phi(ind,:)';
end