#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 24 15:12:17 2024

@author: sam
"""

import numpy as np
from scipy import linalg as la

A = np.random.rand(5,5) # creates a 5x5 matrix A of random numbers
vk = np.random.rand(5,1) # creates a 5x1 vector vk of random numbers



u = A@vk # creates variable u
μk = 0 # creates variable μk
μj = 1 # creates variable μj


# i do not think this works
while abs(μk-μj) > 1e-8: # while change in μ not within tolerance
    u = A@vk # redefines u each iteration
    
    μj = μk # makes them equal
    
    μk = la.norm(u,np.inf) # calculates the largest value in u
    
    vk = u/μk # divides u by the largest value in u

print('largest eigenvalue =',μk) # prints largest eigenvalue
print('with eigenvector =\n',vk) # prints largest eigenvector