-
Notifications
You must be signed in to change notification settings - Fork 0
/
SolveNagumoEquation.m
103 lines (87 loc) · 1.63 KB
/
SolveNagumoEquation.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
tic;
h1 = 0.01; % for x,y
h2 = 0.25; % for t
m = round(1 / h1);
n = (m - 1)^2;
r = h2 / (h1^2);
e = 0.1;
a = 0.5; % normally in typical Nagumo equation a should be in [0, 1]
Tmax = 2;
I = eye(n);
A = -4 * eye(n);
for i = 1 : (n-1)
if (mod(i, m - 1) == 0)
A(i, i + 1) = 0;
A(i + 1, i) = 0;
else
A(i, i + 1) = 1;
A(i + 1, i) = 1;
end
end
for i = 1 : (n - m + 1)
A(i, m - 1 + i) = 1;
A(m - 1 + i, i) = 1;
end
A = I - (e * r * A);
b1 = zeros(n, 1);
k = 1;
for i = 0 : m : m
if (i == m)
k = n - m + 2;
end
for j = 1 : (m-1)
x = i * h1;
y = j * h1;
o = u(x, y);
b1(k) = o;
k = k + 1;
end
end
b1 = e * r * b1;
b2 = zeros(n, 1);
step = m - 2;
k = 1;
for i = 1 : (m-1)
for j = 0: m: m
x = i * h1;
y = j * h1;
o = u(x, y);
b2(k) = o;
if (j == 0)
k = k + step;
else
k = k + 1;
end
end
end
b2 = e * r * b2;
b3 = zeros(n, 1);
k = 1;
for i = 1 : (m - 1)
for j = 1 : (m - 1)
x = i * h1;
y = j * h1;
o = u(x, y);
b3(k) = o * (1 - o) * (o - a);
k = k + 1;
end
end
b3 = h2 * b3;
b = b1 + b2 + b3;
K1 = diag(diag(A));
K2 = inv(K1);
A_prec = inv(K1) * A * K1;
b_prec = K2 * b;
maxIter = 500;
tol = 0.01;
tNew = BiCGSTAB_unprec( A_prec, b_prec, maxIter, tol );
m_t = Tmax/h2;
solution = zeros(n, m_t - 2);
solution(:,1) = tNew;
for k = 2 : (m_t-1);
b = b1 + b2 + tNew;
b_prec = K2 * b;
tNew = BiCGSTAB_unprec( A_prec, b_prec, maxIter, tol );
solution(:, k) = tNew;
end
toc;