Graphics Programs Reference
In-Depth Information
valueof n ):
2
1
00
...
0001
x 1
x 2
x 3
.
x n 2
x n 1
x n
0
0
0
.
0
0
1
12
1
0
...
0000
0
12
1
...
0000
.
.
.
.
.
.
.
.
=
0000
...
12
1
0
0000
...
0
12
1
1
000
...
00
12
Run the programwith n
=
20. The exact solution can be shown to be x i =−
n
/
4
+
i
/
2,
i
=
1
,
2
,...,
n .
Solution In thiscase the iterativeformulas in Eq. (2.35) are
x 1 = ω
( x 2
x n )
/
2
+
(1
ω
) x 1
x i
= ω
( x i 1 +
x i + 1 )
/
2
+
(1
ω
) x i ,
i
=
2
,
3
,...,
n
1
(a)
x n = ω
(1
x 1 +
x n 1 )
/
2
+
(1
ω
) x n
which areevaluatedbythe following function:
functionx=fex2
17(x,omega)
% Iteration formula Eq. (2.35) for Example 2.17.
_
n = length(x);
x(1) = omega*(x(2) - x(n))/2 + (1-omega)*x(1);
fori=2:n-1
x(i) = omega*(x(i-1) + x(i+1))/2 + (1-omega)*x(i);
end
x(n) = omega *(1 - x(1) + x(n-1))/2 + (1-omega)*x(n);
=
The solution can beobtainedwith a single command (note that x
0 is the
starting vector):
>> [x,numIter,omega] = gaussSeidel(@fex2
_
17,zeros(20,1))
resulting in
x=
-4.5000
-4.0000
-3.5000
-3.0000
Search WWH ::




Custom Search