Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Hello World program in Python
- from __future__ import division
- import numpy as np
- from numpy import linalg as LA
- def steep(A, b, x, tol=1e-6, maxit=1e5):
- r=b-np.dot(A,x)
- r_norm=LA.norm(r)
- it=0
- while r_norm>=tol and it<maxit:
- it=it+1
- a=np.dot(r,r)/(np.dot(r, np.dot(A,r)))
- x=x+a*r
- r=b-np.dot(A,x)
- r_norm=LA.norm(r)
- if it==maxit and r_norm>=tol:
- print("Method failed.")
- return x
- A=np.array([[1e-2,0,0],[0,1,0],[0,0,1e2]])
- b=np.array([1,1,1])
- x=np.array([0,0,0])
- theta=steep(A,b,x,tol=1e-6,maxit=1e5)
- print(theta)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement