# inv

inv(M)

Matrix inverse

## Examples

1. Find the inverse of a matrix:

``````julia> M = [1 2; 3 4];
julia> inv(M)
2×2 Array{Float64,2}:
-2.0   1.0
1.5  -0.5``````

This example calculates the inverse of the matrix `M`.

2. Solve a system of linear equations using matrix inversion:

``````julia> A = [2 3; 4 5];
julia> b = [7, 11];
julia> x = inv(A) * b;
julia> x
2-element Array{Float64,1}:
-9.0
7.0``````

Here, `inv(A)` is used to find the inverse of matrix `A`, and then it multiplies with the vector `b` to solve the linear system `Ax = b`.

3. Handle non-invertible matrices:
``````julia> M = [1 2; 2 4];
julia> inv(M)
ERROR: SingularException(2)``````

When a matrix is singular or non-invertible, the `inv` function throws a `SingularException` error. It's important to check for singularity before attempting to find the inverse.

Common mistake example:

``````julia> M = [1 2; 3 4];
julia> inv(M)
ERROR: LinearAlgebra.SingularException(2)``````

In this example, the matrix `M` is not invertible because it is singular. The `inv` function throws a `SingularException` error when a matrix is non-invertible. Ensure that the matrix is invertible before using `inv`.