Ejemplo n.º 1
0
def find_eigenvector(A, tolerance=0.00001):
	guess = [random.random() for _ in A]
	
	while True:
		result = lin_alg.matrix_operate(A, guess)
		length = lin_alg.magnitude(result)
		next_guess = lin_alg.scalar_multiply(1/length, result)
		
		if lin_alg.distance(guess, next_guess) < tolerance:
			return next_guess, length #eigenvector, eigenvalue
			
		guess = next_guess
Ejemplo n.º 2
0
def direction(w):
	mag = lin_alg.magnitude(w)
	return [w_i / mag for w_i in w]