

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A matlab lab project for math 526 students, focusing on the conjugate gradient method for solving the linear system ax = b. It includes an overview of iterative methods, pseudocode for the cg algorithm, and assignments to implement and analyze the method using given matrices and vectors.
Typology: Study Guides, Projects, Research
1 / 2
This page cannot be seen from the preview
Don't miss anything!


MATLAB Lab for Math 526 Project 2
Kamala Diefenthaler ([email protected]) Department of Mathematics
Discuss iterative methods to solve Ax = b, when A is n × n and invertible. Write a Matlab script that implements the Conjugate Gradient method (CG). Find the condition number of a matrix.
Read the Additional Notes page to understand the CG method.
Pseudocode for the conjugate gradient: % Initialize values x=0; r0=b; p0=b; for k >= 1 αk = (rTk− 1 rk− 1 )/(pTk− 1 Apk− 1 ) % step length xk = xk− 1 + αkpk− 1 % approximate solution rk = rk− 1 − αkApk− 1 % error βk = (rTk rk)/(rTk− 1 rk− 1 ) % improvement pk = rk + βkpk− 1 % search direction % Terminate if ||rk|| < or if k = n.
(i) Do one multiplication by A per iteration (pseudocode does two). (ii) Compute only three dot products per iteration (pseudocode does five count- ing the norm of r to check to see if you have converged). (iii) Store only the three vectors xk, rk, and pk to pass to the next iteration (you will also need to store Apk for use within each iteration).
1 April 15, 2009
MATLAB Lab for Math 526 Project 2
(iv) Print or display the value of k for which the program terminated. (v) Store ||rk|| for each k so that after the code has run, you can analyze how xk converged to the solution.
2 April 15, 2009