Main Content

inv

Inverse of symbolic matrix

Syntax

Description

example

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

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 =

( 3 4 1 2 1 4 1 2 1 1 2 1 4 1 2 3 4 )

Compute the inverse of a matrix of symbolic scalar variables.

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

( d a d - b c - b a d - b c - c a d - b c a a d - b c )

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

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

( 16 - 120 240 - 140 - 120 1200 - 2700 1680 240 - 2700 6480 - 4200 - 140 1680 - 4200 2800 )

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

C = [ A 0 2 , 2 0 2 , 2 B ]

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

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

symsAB[2 2]matrixZ = symmatrix(zeros(2))
Z =
                       
                        
                         
                          
                           
                            0
                          
                          
                           
                            
                             2
                           
                           
                            ,
                           
                            
                             2
                           
                          
                         
                        
                       
C = [A Z; Z B]
C =

( A 0 2 , 2 0 2 , 2 B )

Find the inverse of the matrix C

D = inv(C)
D =

( A 0 2 , 2 0 2 , 2 B ) - 1

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

D1 = symmatrix2sym(D)
D1 =

( A 2 , 2 σ 2 - A 1 , 2 σ 2 0 0 - A 2 , 1 σ 2 A 1 , 1 σ 2 0 0 0 0 B 2 , 2 σ 1 - B 1 , 2 σ 1 0 0 - B 2 , 1 σ 1 B 1 , 1 σ 1 ) where σ 1 = B 1 , 1 B 2 , 2 - B 1 , 2 B 2 , 1 σ 2 = A 1 , 1 A 2 , 2 - A 1 , 2 A 2 , 1

Compute the inverse of the matrix polynomial a 0 I 2 + a 1 A + a 2 A 2 , where A is a 2-by-2 matrix.

Create the matrix A and the coefficients a 0 , a 1 , and a 2 as symbolic matrix variables. Create the matrix polynomial as a symbolic matrix functionfwith A , a 0 , a 1 , and a 2 as its parameters.

symsA[2 2]matrixsymsa0a1a2[1 1]matrixsymsf(A,a0,a1,a2)[2 2]matrixkeepargsf(A,a0,a1,a2) = a0*eye(2) + a1*A + a2*A^2
f(A, a0, a1, a2) =
                       
                        
                         
                          
                           
                            
                             
                              
                               
                                
                                 a
                               
                               
                                
                                 0
                               
                              
                             
                             
                             
                             
                              
                               
                                I
                              
                              
                               
                                
                                 2
                               
                              
                             
                            
                           
                           
                            +
                           
                            
                             
                              
                               
                                
                                 a
                               
                               
                                
                                 1
                               
                              
                             
                             
                             
                             
                              
                               
                                A
                              
                             
                            
                           
                           
                            +
                           
                            
                             
                              
                               
                                
                                 a
                               
                               
                                
                                 2
                               
                              
                             
                             
                             
                             
                              
                               
                                
                                 
                                  A
                                
                               
                              
                              
                               
                                2
                              
                             
                            
                           
                          
                         
                        
                       

Find the inverse offusinginv。The result is a symbolic matrix function of typesymfunmatrix

fInv = inv(f)
fInv(A, a0, a1, a2) =
                       
                        
                         
                          
                           
                            
                             
                              
                               
                                
                                 
                                  
                                   
                                    
                                     
                                      a
                                    
                                    
                                     
                                      0
                                    
                                   
                                  
                                  
                                  
                                  
                                   
                                    
                                     I
                                   
                                   
                                    
                                     
                                      2
                                    
                                   
                                  
                                 
                                
                                
                                 +
                                
                                 
                                  
                                   
                                    
                                     
                                      a
                                    
                                    
                                     
                                      1
                                    
                                   
                                  
                                  
                                  
                                  
                                   
                                    
                                     A
                                   
                                  
                                 
                                
                                
                                 +
                                
                                 
                                  
                                   
                                    
                                     
                                      a
                                    
                                    
                                     
                                      2
                                    
                                   
                                  
                                  
                                  
                                  
                                   
                                    
                                     
                                      
                                       A
                                     
                                    
                                   
                                   
                                    
                                     2
                                   
                                  
                                 
                                
                               
                              
                             
                            
                           
                          
                          
                           
                            
                             
                              -
                             
                              1
                            
                           
                          
                         
                        
                       

Evaluate the inverse for the matrix value A = [ 2 - 1 ; - 1 2 ] and the coefficient values a 0 = - 1 , a 1 = 2 , and a 2 = 3 。The result is a symbolic matrix variable of typesymmatrix

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

2 Σ 1 + 3 Σ 1 2 - I 2 - 1 where Σ 1 = ( 2 - 1 - 1 2 )

Convert the result from thesymmatrixdata type to thesymdata type usingsymmatrix2sym。结果是一个矩阵的年代ymbolic numbers.

symmatrix2sym(fEval)
ans =

( 9 64 7 64 7 64 9 64 )

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

之前介绍过的R2006a

expand all

See Also

||