Create symbolic matrix variable
Since R2021a
collapse all in page
Syntax
X = symmatrix('X',[nrow ncol])
X = symmatrix('X',n)
X = symmatrix('X')
X = symmatrix(S)
Description
example
X = symmatrix('X',[nrow ncol])
creates an nrow
-by-ncol
symbolic matrix variable X
. Symbolic matrix variables represent matrices, vectors, and scalars in compact matrix notation. For more information, see Create Symbolic Matrix Variables.
example
X = symmatrix('X',n)
creates an n
-by-n
symbolic matrix variable X
.
X = symmatrix('X')
creates a 1-by-1 symbolic matrix variable X
.
example
X = symmatrix(S)
converts a numeric matrix or a matrix of symbolic scalar variables specified by S
to a symbolic matrix variable X
.
Examples
collapse all
Add Two Matrices
Open Live Script
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.
A = symmatrix('A',[2 3])
A =
B = symmatrix('B',[2 3])
B =
Add the two matrices. The summation of the two symbolic matrix variables is denoted by the matrix notation .
X = A + B
X =
Commutation Relation of Symbolic Matrix Variables
Open Live Script
Symbolic matrix variables represent matrices, vectors, and scalars in compact matrix notation. When representing nonscalars, these variables are noncommutative. When mathematical formulas involve matrices and vectors, writing them using symbolic matrix variables is more concise and clear than writing them componentwise.
Create two symbolic matrix variables.
A = symmatrix('A',[2 2]);B = symmatrix('B',[2 2]);
Check the commutation relation for multiplication between two symbolic matrix variables.
A*B - B*A
ans =
isequal(A*B,B*A)
ans = logical 0
Check the commutation relation for addition between two symbolic matrix variables.
isequal(A+B,B+A)
ans = logical 1
Evaluate Hessian Matrix
Open Live Script
Create 3
-by-3
and 3
-by-1
symbolic matrix variables.
A = symmatrix('A',3)
A =
X = symmatrix('X',[3 1])
X =
Find the Hessian matrix of . Derived equations involving symbolic matrix variables are displayed in typeset as they would be in textbooks.
f = X.'*A*X;H = diff(f,X,X.')
H =
Convert Numeric Matrix to Symbolic Matrix Variable
Open Live Script
Create a Hilbert matrix of order 4. The data type of the matrix is double
.
H = hilb(4)
H = 4×4 1.0000 0.5000 0.3333 0.2500 0.5000 0.3333 0.2500 0.2000 0.3333 0.2500 0.2000 0.1667 0.2500 0.2000 0.1667 0.1429
class(H)
ans = 'double'
Convert the numeric matrix to a symbolic matrix variable. The data type of the converted matrix is symmatrix
.
X = symmatrix(H)
X =
class(X)
ans = 'symmatrix'
Convert Symbolic Matrix Variable to Matrix of Symbolic Scalar Variables
Open Live Script
Create two symbolic matrix variables with size 2
-by-2
.
A = symmatrix('A',2)
A =
B = symmatrix('B',2)
B =
Perform matrix multiplication between A
and B
. The multiplication of the two symbolic matrix variables is represented by the matrix notation .
X = A*B
X =
Convert the symbolic matrix variable X
to a matrix of symbolic scalar variables S
. The multiplication of two matrices of symbolic scalar variables is represented by the elements of the matrix product.
S = symmatrix2sym(X)
S =
Input Arguments
collapse all
X
— Variable name
character vector
Variable name, specified as a character vector. Argument X
must be a valid variable name. That is, X
must begin with a letter and can contain only alphanumeric characters and underscores. To verify that the name is a valid variable name, use isvarname.
Example: x
, y12
, z_1
[nrow ncol]
— Vector or matrix dimensions
vector of integers
Vector or matrix dimensions, specified as a vector of integers. nrow
is the number of rows, and ncol
is the number of columns. As a shortcut, you can create a square symbolic matrix variable by specifying only one integer. For example, X = symmatrix('X',3)
creates a square 3
-by-3
symbolic matrix variable.
Example: [2 3]
, [2,3]
S
— Numeric matrix or matrix of symbolic scalar variables to be converted
number | numeric matrix | symbolic scalar variable | matrix of symbolic scalar variables
Numeric matrix or matrix of symbolic scalar variables to be converted to symbolic matrix variable, specified as a number, numeric matrix, symbolic scalar variable, or a matrix of symbolic scalar variables.
Example: 10
, eye(3)
, pi
, hilb(3)
Limitations
Differentiation functions, such as jacobian and laplacian, currently do not accept symbolic matrix variables as input. To evaluate differentiation with respect to vectors and matrices, you can use the diff function instead.
To show all the functions in Symbolic Math Toolbox™ that accept symbolic matrix variables as input, use the command
methods symmatrix
.
Alternative Functionality
Alternative Approaches for Creating Symbolic Matrix Variables
To create several symbolic matrix variables in one function call, use syms var1 ... varN [nrow ncol] matrix
. For more details, see syms.
Version History
Introduced in R2021a
See Also
syms | sym | symfun | symfunmatrix | str2sym | symvar | symmatrix2sym
Topics
- Create Symbolic Numbers, Variables, and Expressions
- Create Symbolic Functions
- Create Symbolic Matrices
- Create Symbolic Matrix Variables
- Use Symbolic Objects to Represent Mathematical Objects
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本 (日本語)
- 한국 (한국어)
Contact your local office