# NLA-5.1

## 2436 days 전, jhlee2chn 작성

Algorithm 5.1.1  (Steepest Descent Method for solving LSE with p.d. matrix)

A = matrix(RDF,[[16.0, 4.0, 8.0, 4.0], [4.0, 10.0, 8.0, 4.0], [8.0, 8.0, 12.0, 10.0], [4.0, 4.0, 10.0, 12.0]]) print "A=" print A b = vector(RDF,[32.0, 26.0, 38.0, 30.0]) print "b=" print b # Steepest Descent x = 10*random_vector(RDF, 4) tol = 10^(-8) r = b-A*x k = 0 while r.norm(Infinity) > tol: k = k+1 q = A*r alp = r.inner_product(r)/(r.inner_product(q)) x = x + alp*r r=b-A*x print "x=", x print "||r||=", r.norm(Infinity) print "exact solution=", A.solve_right(b)
 A= [16.0 4.0 8.0 4.0] [ 4.0 10.0 8.0 4.0] [ 8.0 8.0 12.0 10.0] [ 4.0 4.0 10.0 12.0] b= (32.0, 26.0, 38.0, 30.0) x= (1.00000000863, 1.00000001743, 0.999999963693, 1.0000000224) ||r||= 9.89016868402e-09 exact solution= (1.0, 1.0, 1.0, 1.0) A= [16.0 4.0 8.0 4.0] [ 4.0 10.0 8.0 4.0] [ 8.0 8.0 12.0 10.0] [ 4.0 4.0 10.0 12.0] b= (32.0, 26.0, 38.0, 30.0) x= (1.00000000863, 1.00000001743, 0.999999963693, 1.0000000224) ||r||= 9.89016868402e-09 exact solution= (1.0, 1.0, 1.0, 1.0)