eigenvalue.py

Created by matt-numworks

Created on January 09, 2025

871 Bytes


def mat_mult(A, B):
    # Matrix multiplication
    result = [[sum(a * b for a, b in zip(A_row, B_col)) for B_col in zip(*B)] for A_row in A]
    return result

def mat_sub(A, B):
    # Matrix subtraction
    result = [[A[i][j] - B[i][j] for j in range(len(A[0]))] for i in range(len(A))]
    return result

def identity_matrix(n):
    # Create an identity matrix of size n
    I = [[1 if i == j else 0 for j in range(n)] for i in range(n)]
    return I

# Example matrix
A = [[4, 2],
     [1, 3]]

# For simplicity, let's assume a known eigenvalue (you can use a method to find eigenvalues)
eigenvalue = 5

# Eigenvalue matrix
Lambda = [[eigenvalue if i == j else 0 for j in range(len(A))] for i in range(len(A))]

# (A - λI)
I = identity_matrix(len(A))
A_minus_lambdaI = mat_sub(A, Lambda)

print("A - λI:")
for row in A_minus_lambdaI:
    print(row)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.