3.1. STEADY STATE AND ITERATIVE METHODS 103
3.1.5 Implementation
The cooling fin problem of the Section 2.3 is reconsidered with the tridiagonal
algorithm replaced by the SOR iterative method. Although SOR converges
much more rapidly than Jacobi, one should use the tridiagonal algorithm for
tridiagonal problems. S ome calculations are done to illustrate convergence of
the SOR method as a function of the SOR parameter,
$. Also, numerical
exp eriments with variable thickness,
W , of the fin are done.
The M
AT LAB code fin1d.m, which was described in Section 2.3, will be used
to call the following user defined M
ATLAB function sorfin.m. In fin1d.m on line
38 x = wulg(q> d> e> f> g) should be replaced by [x> p> z] = vrui lq(q> d> e> f> g),
where the solution will be given by the vector
x, p is the number of SOR steps
required for convergence and
z is the SOR parameter. In sorfin.m the accuracy
of the SOR method will be controlled by the tolerance or error parameter,
hsv
on line 7, and by the SOR parameter, z on line 8. The initial guess is given
in lines 10-12. The SOR method is executed in the while loop in lines 13-39
where p is the loop index. The counter for the number of nodes that satisfy
the error test is initialized in line 14 and updated in lines 20, 28 and 36. SOR
is done for the left node in lines 15-21, for the interior nodes in lines 22-30 and
for the right node in lines 31-37. In all three cases the
p + 1 iterate of the
unknowns over-writes the
p
wk
iterate of the unknowns. The error test requires
the absolute value of the dierence between successive iterates to be less than
hsv. When qxpl equals q, the while loop will be terminated. The while loop
will also b e terminated if the loop counter
p is too large, in this case larger
than
pd{p = 500.
MATLAB Code sorfin.m
1. %
2. % SOR Algorithm for Tridiagonal Matrix
3. %
4. function [u, m, w] =sorfin(n,a,b,c,d)
5. maxm = 500; % maximum iterations
6. numi = 0; % counter for nodes satisfying error
7. eps = .1; % error tolerance
8. w = 1.8; % SOR parameter
9. m = 1;
10. for i =1:n
11. u(i) = 160.; % initial guess
12. end
13. while ((numi
?n)*(m?maxm)) % begin SOR loop
14. numi = 0;
15. utemp = (d(1) -c(1)*u(2))/a(1); % do left node
16. utemp = (1.-w)*u(1) + w*utemp;
17. error = abs(utemp - u(1)) ;
18. u(1) = utemp;
19. if (error?eps)
© 2004 by Chapman & Hall/CRC