% Linear Algebra: Theory and Applications % Ward Cheney & David Kincaid % JBPub.com (c) 2008 % File: exp8-3-4.m % Example 8.3.4 % format long A=[2 -0.3 -0.2; -0.3 2 -0.1; -0.2 -0.1 2] b=[7;5;3] epsi=1.0e-15; kmax=20; %=============================================================== % Conjugate gradient algorithm %=============================================================== k=0; x = [0;0;0] r = b - A*x; rho = r'*r; while (sqrt(rho)>epsi*sqrt(b'*b) & k