% Program Numerical Analysis % Jan 10th HW4 clc clear A=[5 -2 3;-3 9 1;2 -1 -7] b=[-1;2;3]; x0=[0;0;0]; x=x0; Iterations=1e6; ApproximateValue=1e-10; tic gamma=b-A*x; Q=gamma; rs=gamma'*gamma; disp('Calculating...') for i=1:Iterations Ap=A*Q; alpha=rs/(Q'*Ap); x=x+alpha*Q; gamma=gamma-alpha*Ap; rsnew=gamma'*gamma; if sqrt(rsnew)