-
Notifications
You must be signed in to change notification settings - Fork 0
/
steady_state_gs.m
53 lines (37 loc) · 1.04 KB
/
steady_state_gs.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 [ T ] = steady_state_gs(error,tol,nx,ny,Told)
%creating mesh
x = linspace(0,1,nx);
y = x;
dx = x(2) - x(1);
dy = dx;
T_gs = Told ;
%gauss seidel method
k = 2*(dx^2+dy^2)/(dx^2 * dy^2);
gs_iter = 1;
%convergence loop
while(error > tol)
%space loop
for i = 2:nx-1
for j = 2:ny-1
term3 = (Told(i+1,j) + T_gs(i-1,j))/(dx^2);
term4 = (Told(i,j+1) + T_gs(i,j-1))/(dy^2);
T_gs(i,j) = term3/k + term4/k ;
end
end
%calculating error
error = max(max(abs(Told - T_gs)));
%updating the value
Told = T_gs;
gs_iter = gs_iter + 1;
%plotting of results
figure(2);
contourf(T_gs,10);
set(gca,'yDIR','reverse');
colorbar;
title_text = sprintf('GS iteratons = %d',gs_iter);
title(title_text)
xlabel('x');
ylabel('y');
pause(0.03)
end
end