Main Content

inv

Inverse of symbolic matrix

Description

example

D = inv(A) returns the inverse of a symbolic matrix A.

Examples

collapse all

Compute the inverse of a matrix of symbolic numbers.

A = sym([2 -1 0; -1 2 -1; 0 -1 2]);
D = inv(A)
D = 

(34121412112141234)

Compute the inverse of a matrix of symbolic scalar variables.

syms a b c d
A = [a b; c d];
D = inv(A)
D = 

(dad-bc-bad-bc-cad-bcaad-bc)

Compute the inverse of the Hilbert matrix that contains symbolic numbers.

D = inv(sym(hilb(4)))
D = 

(16-120240-140-1201200-27001680240-27006480-4200-1401680-42002800)

Find the inverse of a 4-by-4 block matrix

C=[A02,202,2B]

where A and B are 2-by-2 submatrices. The notation 02,2 represents a 2-by-2 submatrix of zeros.

Use symbolic matrix variables to represent the submatrices in the block matrix.

syms A B [2 2] matrix
Z = symmatrix(zeros(2))
Z = 02,2
C = [A Z; Z B]
C = 

(A02,202,2B)

Find the inverse of the matrix C.

D = inv(C)
D = 

(A02,202,2B)-1

To show the elements of the inverse matrix, convert the result from a symbolic matrix variable to symbolic scalar variables using symmatrix2sym.

D1 = symmatrix2sym(D)
D1 = 

(A2,2σ2-A1,2σ200-A2,1σ2A1,1σ20000B2,2σ1-B1,2σ100-B2,1σ1B1,1σ1)where  σ1=B1,1B2,2-B1,2B2,1  σ2=A1,1A2,2-A1,2A2,1

Compute the inverse of the matrix polynomial a0I2+a1A+a2A2, where A is a 2-by-2 matrix.

Create the matrix A and the coefficients a0, a1, and a2 as symbolic matrix variables. Create the matrix polynomial as a symbolic matrix function f with A, a0, a1, and a2 as its parameters.

syms A [2 2] matrix
syms a0 a1 a2 [1 1] matrix
syms f(A,a0,a1,a2) [2 2] matrix keepargs
f(A,a0,a1,a2) = a0*eye(2) + a1*A + a2*A^2
f(A, a0, a1, a2) = a0I2+a1A+a2A2

Find the inverse of f using inv. The result is a symbolic matrix function of type symfunmatrix.

fInv = inv(f)
fInv(A, a0, a1, a2) = a0I2+a1A+a2A2-1

Evaluate the inverse for the matrix value A=[2-1;-12] and the coefficient values a0=-1, a1=2, and a2=3. The result is a symbolic matrix variable of type symmatrix.

Aval = [2 -1; -1 2];
fEval = fInv(Aval,-1,2,3)
fEval = 

2Σ1+3Σ12-I2-1where  Σ1=(2-1-12)

Convert the result from the symmatrix data type to the sym data type using symmatrix2sym. The result is a matrix of symbolic numbers.

symmatrix2sym(fEval)
ans = 

(964764764964)

Input Arguments

collapse all

Input matrix, specified as a square numeric matrix, square matrix of symbolic scalar variables, square symbolic matrix variable, square symbolic matrix function, or symbolic expression with square size.

Data Types: single | double | sym | symmatrix | symfunmatrix

Tips

  • Matrix computations involving many symbolic variables can be slow. To increase the computational speed, reduce the number of symbolic variables by substituting the given values for some variables.

Version History

Introduced before R2006a

expand all

See Also

| |