AORC-Seminar (LCG)

1730 days 전, jhlee2chn 작성

Algorithm  (Conjugate Gradient Method for solving LSE with p.d. matrix)

G = 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 "G=" print G b = vector(RDF,[32.0, 26.0, 38.0, 30.0]) print "b=" print b # Conjugate Gradient x = 10*random_vector(RDF, 4) tol = 10^(-8);g = G*x+b;k = 0 while g.norm(Infinity) > tol: k = k + 1 if k == 1: d = -g else: bet=g.inner_product(g)/g_old.inner_product(g_old) d = -g + bet*d q = G*d alp = g.inner_product(g)/(d.inner_product(q)) x = x + alp*d;g_old=g;g = g+alp*q print "x=", x print "||g||=", g.norm(Infinity) print "exact solution=", G.solve_right(-b) print k 
       
G=
[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.0, -1.0, -1.0, -1.0)
||g||= 3.14448467265e-12
exact solution= (-1.0, -1.0, -1.0, -1.0)
4
G=
[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.0, -1.0, -1.0, -1.0)
||g||= 3.14448467265e-12
exact solution= (-1.0, -1.0, -1.0, -1.0)
4

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

G = 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 "G=" print G 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) g = G*x+b k = 0 while g.norm(Infinity) > tol: k = k+1 q = G*g alp = g.inner_product(g)/(g.inner_product(q)) x = x - alp*g g=G*x+b print "x=", x print "||g||=", g.norm(Infinity) print "exact solution=", G.solve_right(-b) print k 
       
G=
[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.00000000711, -1.00000001428, -0.999999970409, -1.00000001835)
||g||= 9.8726573583e-09
exact solution= (-1.0, -1.0, -1.0, -1.0)
1225
G=
[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.00000000711, -1.00000001428, -0.999999970409, -1.00000001835)
||g||= 9.8726573583e-09
exact solution= (-1.0, -1.0, -1.0, -1.0)
1225