Changeset 438 for inundation/ga/storm_surge/pyvolution/cg_solve.py
- Timestamp:
- Oct 21, 2004, 11:54:49 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/cg_solve.py
r435 r438 1 1 import exceptions 2 class VectorShapeError(exceptions.Exception): 3 """ 4 Setup Exception for routine conjugate_gradient 5 """ 6 def __init__(self,args=None): 7 self.args = args 8 9 10 2 class VectorShapeError(exceptions.Exception): pass 11 3 12 4 13 5 def conjugate_gradient(A,b,x0,imax=2000,tol=1.0e-8,iprint=0): 14 # 15 # Try to solve linear equation Ax = b using 16 # conjugate gradient method 17 # 18 # Input 19 # A: matrix or function which applies a matrix, assumed symmetric 20 # b: right hand side 21 # x0: inital guess 22 # imax: max number of iterations 23 # tol: tolerance used for residual 24 # 25 # Output 26 # x: approximate solution 27 # i: number of iterations 28 # 6 """ 7 Try to solve linear equation Ax = b using 8 conjugate gradient method 9 10 Input 11 A: matrix or function which applies a matrix, assumed symmetric 12 b: right hand side 13 x0: inital guess 14 imax: max number of iterations 15 tol: tolerance used for residual 16 17 Output 18 x: approximate solution 19 """ 29 20 30 21 #if nargin<3 … … 37 28 b = asarray(b, typecode=Float) 38 29 x0 = asarray(x0, typecode=Float) 30 #A = asarray(A, typecode=Float) 39 31 40 print "A shape",A.shape[0]41 print "b shape",len(b.shape)42 print "x0 shape",x0.shape[0]32 #print "A shape",A.shape 33 #print "b shape",len(b.shape) 34 #print "x0 shape",x0.shape[0] 43 35 44 36 if len(b.shape) != 1 :
Note: See TracChangeset
for help on using the changeset viewer.