Professional Documents
Culture Documents
k
=
(r
R
, r
R
)
(r
R
, Ad
R
)
. (5)
(Hint: Use the fact that successive residuals in this method are orthogonal.)
ii) Show that if the search direction is d
k
= r
k
+ [
k-1
d
k-1
then
[
k-1
=
(r
R
, r
R
)
(r
R-1
, r
R-1
)
. (6)
(Hint: Use the conjugacy properties of d
k
and the results you obtained in 2.i)
3. [50 points]
Consider the linear system of equations Ax = b, where
A
]
= _
1
+]-1
i i = ]
1 clsc
_ for 1 i, ] 6 and b =
l
l
l
l
l
l
1
2
u
2
1
1
1
1
1
1
1
1
.
Construct the following subroutines. Whenever a tolerance is needed for your computations use the value e 1u
-5
; use the
difference between two successive iterations as your convergence criterion.
i) [10 points]
Jacobi's method.
ii) [10 points]
GS and SOR methods. Use = u.9 for SOR.
iii) [10 points]
Steepest descent method.
iv) [10 points]
CG method.
v) [10 points]
a) Do all iterative methods converge? Explain the results you obtained by using each method.
b) What is the optimal value of for the SORmethod to converge in the least possible iterations? To answer, plot the number
of iterations required by your SOR code to convergence as a function of , if e |u.1,1.9]. Use J = u.u1.
Remark: Recall that you can only use essential built-in commands in MATLAB such as size, length, zeros, eye and
for/if statements. Any multiplication, needs to be in a component form(i.e. A( i , j ) *B( j ) ). Remember to comment
important lines of your code. You should use the subroutines you made in previous homeworks related to all
multiplications of e.g. constant by a vector, etc. Modify the following script to prepare your codes:
f unct i on [ xf i nal , i t ] =J acobi f ( A, b) ; %Si mi l ar l y def i ne GSf ( A, b) , SORf ( A, b) , St eepest f ( A, b) and
Conj ugat ef ( A, b)
m=l engt h( b) ;
maxi t =100; %Maxi mumal l owed number of i t er at i ons
i t =0; %I t er at i on i ndex
cr i t =i nf ; %Cover gence cr i t er i on ( i s def i ned l at er )
.
.
.
whi l e cr i t >10e- 5 & i t <maxi t ; %St ar t t he i t er at i ve scheme
.
.
.
.
end
i f i t ==maxi t
i nf o=' Maxi mumi t er at i on r eached' ;
el se
st r i ng_i t =num2st r ( i t ) ;
i nf o=[ ' Conver ged at i t er at i on ' st r i ng_i t ] %Number of i t er at i on t o conver gence
end