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.

See Also

Ac_ldiv_B, Ac_ldiv_Bc, Ac_mul_B, Ac_mul_Bc, Ac_rdiv_B, Ac_rdiv_Bc, At_ldiv_B, At_ldiv_Bt, At_mul_B, At_mul_Bt, At_rdiv_B, At_rdiv_Bt, A_ldiv_Bc, A_ldiv_Bt, A_mul_B!, A_mul_Bc, A_mul_Bt, A_rdiv_Bc, A_rdiv_Bt, Bidiagonal, cond, conv2, det, diag, diagind, diagm, diff, eig, eigvals, eigvecs, expm, eye, full, inv, isdiag, ishermitian, isposdef, isposdef!, issym, istril, istriu, logabsdet, logdet, lyap, norm, qrfact, rank, repmat, rot180, rotl90, rotr90, sortrows, sqrtm, SymTridiagonal, trace, Tridiagonal, tril, tril!, triu, triu!, writedlm,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: