Solved: PV2 Laplacian Eigenvalue Problem in Python

python # Author: Alberto # PV2 - Laplacian Eigenvalue Approximation on a 2D Square Domain import numpy as np from scipy.sparse import diags from scipy.sparse.linalg import eigsh def solve_pv2_laplacian(n): N = n * n main_diag = 4 * np.ones(N) side_diag = -1 * np.ones(N - 1) side_diag[np.arange(1, N) % n == 0] = 0 up_down_diag = -1 * np.ones(N - n) diagonals = [main_diag, side_diag, side_diag, up_down_diag, up_down_diag] offsets = [0, -1, 1, -n, n] A = diags(diagonals, offsets, format='csr') eigenvalues, _ = eigsh(A, k=1, which='SM') # Smallest magnitude eigenvalue return eigenvalues[0] # Example usage n = 30 # Grid resolution (can be increased for higher precision) result = solve_pv2_laplacian(n) print("Approximated smallest eigenvalue for PV2:", result)

Mar 31, 2025 - 22:49
 0
Solved: PV2 Laplacian Eigenvalue Problem in Python

python
# Author: Alberto
# PV2 - Laplacian Eigenvalue Approximation on a 2D Square Domain

import numpy as np
from scipy.sparse import diags
from scipy.sparse.linalg import eigsh

def solve_pv2_laplacian(n):
    N = n * n
    main_diag = 4 * np.ones(N)
    side_diag = -1 * np.ones(N - 1)
    side_diag[np.arange(1, N) % n == 0] = 0
    up_down_diag = -1 * np.ones(N - n)

    diagonals = [main_diag, side_diag, side_diag, up_down_diag, up_down_diag]
    offsets = [0, -1, 1, -n, n]

    A = diags(diagonals, offsets, format='csr')
    eigenvalues, _ = eigsh(A, k=1, which='SM')  # Smallest magnitude eigenvalue
    return eigenvalues[0]

# Example usage
n = 30  # Grid resolution (can be increased for higher precision)
result = solve_pv2_laplacian(n)
print("Approximated smallest eigenvalue for PV2:", result)