(Before you tell me, yes, I know you should never invert the matrix. Unfortunately for my calculations, I have a matrix which I have constructed, and it must be inverted somehow.)
I have a large matrix M
which is ill-conditioned. numpy.linalg.cond(M)
outputs a value of magnitude e+22
. The matrix M
is shaped (1000,1000)
.
Naturally, numpy.linalg.inv()
will result in many precision errors. So, I have used numpy.linalg.solve()
to invert the matrix.
Consider that the matrix inverse A^{-1}
is defined by A * A^{-1} = Identity
.
numpy.linalg.solve()
computes the “exact” solution, x, of the well-determined, i.e., full rank, linear matrix equation ax = b.
So, I define the identity matrix:
import numpy as np
iddmatrix = np.identity(100)
and solve:
inverse = np.linalg.solve(M, iddmatrix)
However, because my matrix is so large and so ill-conditioned, np.linalg.solve()
will not give the "exact solution". I need another method to invert the matrix.
- What is the standard way to implement such an inverse with SVD?
- How could I make this ill-conditioned matrix....well-defined?
Any recommendations are appreciated. Thanks!
svd
, you can easily use it to calculate a pseudo inverse. The pseudo inverse will be your inverse if your input matrix is invertiblenumpy.linalg.pinv
(docs.scipy.org/doc/numpy/reference/generated/…)?