implementing inconsistent results using np.linalg.solve for large matrices
I'm writing unit tests and I'm working on solving a system of linear equations using NumPy's `np.linalg.solve` function, but I'm experiencing inconsistent results when the matrix size increases..... My coefficients matrix is `A` and the constants vector is `b`, both of which are generated dynamically. Here's a snippet of the code I am using: ```python import numpy as np # Generate a random 10x10 matrix and a random constants vector np.random.seed(0) # For reproducibility A = np.random.rand(10, 10) b = np.random.rand(10) # Solve the linear equations x = np.linalg.solve(A, b) print(x) ``` When I attempt to increase the size of the matrix to 100x100, I use: ```python A_large = np.random.rand(100, 100) b_large = np.random.rand(100) x_large = np.linalg.solve(A_large, b_large) print(x_large) ``` For the larger matrix, however, the output seems more sensitive to the random seed, leading to significantly different results on subsequent runs. I also noticed that when `A_large` becomes singular (determinant close to zero), I get a `LinAlgError` with the message `Singular matrix`. I've tried checking the condition number of my matrix using `np.linalg.cond(A_large)` to ensure it's not too high, but I still get unexpected results when using `np.linalg.solve` on larger matrices. Is there a more reliable method to handle larger matrices, especially when they might be ill-conditioned or singular? Are there specific practices I should follow to avoid inconsistencies in results for large systems? My development environment is Linux. Thanks in advance! Any ideas what could be causing this?