Main Content

symmatrix2sym

Convert symbolic matrix variable to array of scalar variables

Since R2021a

Description

example

S = symmatrix2sym(M) converts a symbolic matrix variable M of type symmatrix to an array of symbolic scalar variables S of type sym.

The output array is the same size as the input symbolic matrix variable and its components are filled with automatically generated elements. For example, syms M [1 3] matrix; S = symmatrix2sym(M) creates the matrix S = [M1_1, M1_2, M1_3]. The generated elements M1_1, M1_2, and M1_3 do not appear in the MATLAB® workspace.

Examples

collapse all

Create two symbolic matrix variables with size 2-by-3. Nonscalar symbolic matrix variables are displayed as bold characters in the Live Editor and Command Window.

syms A B [2 3] matrix
A
A = A
B
B = B

Add the two matrices. The result is represented by the matrix notation A+B.

X = A + B
X = A+B

The data type of X is symmatrix.

class(X)
ans = 
'symmatrix'

Convert the symbolic matrix variable X to a matrix of symbolic scalar variables Y. The result is denoted by the sum of the matrix components.

Y = symmatrix2sym(X)
Y = 

(A1,1+B1,1A1,2+B1,2A1,3+B1,3A2,1+B2,1A2,2+B2,2A2,3+B2,3)

The data type of Y is sym.

class(Y)
ans = 
'sym'

Show that the converted result in Y is equal to the sum of two matrices of symbolic scalar variables.

syms A B [2 3]
Y2 = A + B
Y2 = 

(A1,1+B1,1A1,2+B1,2A1,3+B1,3A2,1+B2,1A2,2+B2,2A2,3+B2,3)

isequal(Y,Y2)
ans = logical
   1

Create 3-by-3 and 3-by-1 symbolic matrix variables.

syms A [3 3] matrix
syms X [3 1] matrix

Find the Hessian matrix of XTAX.

f = X.'*A*X;
H = diff(f,X,X.')
H = AT+A

Convert the result from a symbolic matrix variable H to a matrix of symbolic scalar variables S.

S = symmatrix2sym(H)
S = 

(2A1,1A1,2+A2,1A1,3+A3,1A1,2+A2,12A2,2A2,3+A3,2A1,3+A3,1A2,3+A3,22A3,3)

Create a 1-by-3 symbolic matrix variable that represents a vector.

syms A [1 3] matrix

Find the 2-norm of the vector A. The result is a symbolic matrix variable with symmatrix data type.

N = norm(A)
N = A2
class(N)
ans = 
'symmatrix'

Convert N to a symbolic scalar variable to express the 2-norm in terms of the components of A. The result is a symbolic scalar variable with sym data type.

N = symmatrix2sym(N)
N = 

|A1,1|2+|A1,2|2+|A1,3|2

class(N)
ans = 
'sym'

Create two vectors of size 3-by-1 as symbolic matrix variables.

syms A B [3 1] matrix

Find the dot product of the two vectors by evaluating transpose(A)*B.

C = transpose(A)*B
C = ATB

Convert C to a symbolic scalar variable to express the dot product in terms of the components of A and B.

C = symmatrix2sym(C)
C = A1B1+A2B2+A3B3

Create two 2-by-3 symbolic matrix variables.

syms A B [2 3] matrix

Concatenate the two matrices vertically using the command vertcat(A,B) or [A; B].

C = [A; B]
C = 

(AB)

Convert C to a matrix of symbolic scalar variables.

C = symmatrix2sym(C)
C = 

(A1,1A1,2A1,3A2,1A2,2A2,3B1,1B1,2B1,3B2,1B2,2B2,3)

Input Arguments

collapse all

Input, specified as a symbolic matrix variable.

Data Types: symmatrix

Tips

  • To show all the functions in Symbolic Math Toolbox™ that accept symbolic matrix variables as input, use the command methods symmatrix.

Version History

Introduced in R2021a