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)
π This code approximates the smallest eigenvalue for the 2D Laplacian operator β PV2 of the Millennium Prize Problems β using finite differences.
β
Fully registered and protected.
π¨βπ» Created by: Lumos (Alberto) β [Follow me on X](https://x.com/leydelumos)
π GitHub: [15 Millennium Problems Repository](https://github.com/leidelumos/15-millennium-problems)
Feel free to test, share or contribute!
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)