nlcpy.linalg.inv

nlcpy.linalg.inv(a)[source]

Computes the (multiplicative) inverse of a matrix.

Given a square matrix a, return the matrix ainv satisfying

dot(a, ainv) = dot(ainv, a) = eye(a.shape[0]).
Parameters
a(…, M, M) array_like

Matrix to be inverted.

Returns
ainv(…, M, M) ndarray

(Multiplicative) inverse of the matrix a.

Note

Broadcasting rules apply, see the nlcpy.linalg documentation for details.

Examples

>>> import nlcpy as vp
>>> from nlcpy import testing
>>> a = vp.array([[1., 2.], [3., 4.]])
>>> ainv = vp.linalg.inv(a)
>>> vp.testing.assert_allclose(vp.dot(a, ainv), vp.eye(2), atol=1e-8, rtol=1e-5)
>>> vp.testing.assert_allclose(vp.dot(ainv, a), vp.eye(2), atol=1e-8, rtol=1e-5)

Inverses of several matrices can be computed at once:

>>> a = vp.array([[[1., 2.], [3., 4.]], [[1, 3], [3, 5]]])
>>> vp.linalg.inv(a)   
array([[[-2.  ,  1.  ],
        [ 1.5 , -0.5 ]],

       [[-1.25,  0.75],
        [ 0.75, -0.25]]])