dot ( A, x ) #check L2-norm of the residual for convergence if ( nl. copy ( x ) for iter in range ( maxIter ) : #calculate residual res = f - numpy. shape != n ) : print ( "Error! Incompatible array and vector sizes." ) return f #Set up a loop to iterate until we converge to a solution or we reach the max number of iterations xnew = numpy. size #Begin bychecking for compatiable matrix and rhs sizes if ( A. linalg as nl def jacobi ( A, f, x, maxIter = 100, tol = 1.0e-4 ) : #inputs: #A is a nXn matrix #f is is a right-hand-side vector of length n #x is initial guess at the solution to Ax = f #maxIter (optional) is max number of Jacobi iterations #tol (optional) is the desired accuracy in terms of the L2-norm of the residual (f-Ax) n = f.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |