-
Notifications
You must be signed in to change notification settings - Fork 1
/
Nm_oper_sor5.m
71 lines (62 loc) · 2.47 KB
/
Nm_oper_sor5.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
function [output] = Nm_oper_sor5(i,j,A5,u,b)
[m,n] = size(b);
if i > 1 && i < m, if j > 1 && j < n
sum4 = A5(1,i,j)*u(i,j-1) ...
+A5(2,i,j)*u(i-1,j) ...
+A5(4,i,j)*u(i+1,j) ...
+A5(5,i,j)*u(i,j+1);
output = (b(i,j)-sum4)/A5(3,i,j);
end, end
% if i ==1, if j == 1
% sum4 = A5(4,i,j)*u(i+1,j) ...
% +A5(5,i,j)*u(i,j+1);
% output = (b(i,j)-sum4)/A5(3,i,j);
% correction = omega*(output - u(i,j));
% u(i,j) = u(i,j)+correction;
% err = max(err,abs(correction));
% end,end
if i == m, if j == 1
sum4 = A5(2,i,j)*u(i-1,j) ...
+A5(5,i,j)*u(i,j+1);
output = (b(i,j)-sum4)/A5(3,i,j);
end, end
if i == 1, if j == n
sum4 = A5(1,i,j)*u(i,j-1) ...
+A5(4,i,j)*u(i+1,j);
output = (b(i,j)-sum4)/A5(3,i,j);
end,end
% (m ,n)
if i == m, if j == n
sum4 = A5(1,i,j)*u(i,j-1) ...
+A5(2,i,j)*u(i-1,j);
output = (b(i,j)-sum4)/A5(3,i,j);
end, end
% left-hand side
if i ~= 1 && i ~= m, if j == 1
sum4 = A5(2,i,j)*u(i-1,j) ...
+A5(4,i,j)*u(i+1,j) ...
+A5(5,i,j)*u(i,j+1);
output = (b(i,j)-sum4)/A5(3,i,j);
end,end
% right-hand side
if i ~= 1 && i ~= m, if j == n
sum4 = A5(1,i,j)*u(i,j-1) ...
+A5(2,i,j)*u(i-1,j) ...
+A5(4,i,j)*u(i+1,j);
output = (b(i,j)-sum4)/A5(3,i,j);
end,end
% up-hand side
if i == 1, if j ~= 1 && j ~= n
sum4 = A5(1,i,j)*u(i,j-1) ...
+A5(4,i,j)*u(i+1,j) ...
+A5(5,i,j)*u(i,j+1);
output = (b(i,j)-sum4)/A5(3,i,j);
end,end
% down-hand side
if i == m, if j ~= 1 && j ~= n
sum4 = A5(1,i,j)*u(i,j-1) ...
+A5(2,i,j)*u(i-1,j) ...
+A5(5,i,j)*u(i,j+1);
output = (b(i,j)-sum4)/A5(3,i,j);
end,end
end