MatrixSymbol[a]
represents a matrix with name a.
MatrixSymbol[a,{m,n}]
represents an mn matrix.
MatrixSymbol[a,{m,n},dom]
represents a matrix with elements in the domain dom.
MatrixSymbol[a,{m,n},dom, sym]
represents a matrix with the symmetry sym.
MatrixSymbol
MatrixSymbol[a]
represents a matrix with name a.
MatrixSymbol[a,{m,n}]
represents an mn matrix.
MatrixSymbol[a,{m,n},dom]
represents a matrix with elements in the domain dom.
MatrixSymbol[a,{m,n},dom, sym]
represents a matrix with the symmetry sym.
Details
- The name a in MatrixSymbol[a,{m,n},dom, sym] can be any expression.
- Valid dimension specifications m and n in MatrixSymbol[a,{m,n},dom, sym] are positive integers. It is also possible to work with symbolic dimension specifications.
- Element domain specifications dom in MatrixSymbol[a,{m,n},dom, sym] include:
-
Complexes complex numbers Integers integers Reals real numbers NonNegativeReals real numbers x with x≥0 PositiveReals real numbers x with x>0 - Some symmetry specifications have names:
-
Symmetric[{1,2}] symmetric matrix Antisymmetric[{1,2}] antisymmetric matrix - In arithmetic and many other functions that work with lists, MatrixSymbol objects do not automatically combine with other list arguments.
- Optimization functions, equation solvers and D recognize that MatrixSymbol objects represent vector variables.
Examples
open all close allBasic Examples (1)
Assign the value of the variable a to represent an mn matrix with name "a":
a = MatrixSymbol["a", {m, n}]Arithmetic operations recognize that a is not a scalar:
a + b + {1, 2}a - aD recognizes that a is a matrix variable:
D[Transpose[a], a]Scope (5)
Compute derivatives with respect to a matrix variable:
a = MatrixSymbol["a", {m, n}];D[a, a]D[Tr[a], a]D[Inverse[a], a]Compute derivatives involving matrix-valued functions:
a = MatrixSymbol["a", {m, n}];D[a[x].a[x], x]D[Det[a[x]], x]This requires a real-valued matrix:
a = MatrixSymbol["a", {m, n}, Reals];D[Norm[a, "Frobenius"], a]Use a matrix variable in optimization:
a = MatrixSymbol["a", {2, 2}];NMinimize[{{1, 2}.a.{3, 4}, Norm[a, "Frobenius"] ^ 2 <= 1}, a]Minimize[{Det[a], {1, 2}.a.{3, 4} == 5 && a.{6, 7} == {8, 9} && {1, 9}.a.{3, 7} >= 5}, a]Solve equations and inequalities involving a matrix variable:
a = MatrixSymbol["a", {2, 2}];Solve[a.{1, 2} == {3, 4} && Det[a] == 5 && Tr[a] == 6, a]FindInstance[Det[a] == 1 && VectorGreater[{a.{1, 2}, {3, 4}}], a]Applications (4)
Approximate the determinant of a perturbed matrix:
a = RandomInteger[{-10 ^ 6, 10 ^ 6}, {7, 7}] / 10 ^ 6;
eps = RandomInteger[{-10 ^ 6, 10 ^ 6}, {7, 7}] / 10 ^ 16;t0 = Det[a];N[Det[a + eps] - t0, 20]m = MatrixSymbol["m", {7, 7}];
d1 = D[Det[m], m]t1 = t0 + ArrayDot[d1 /. m -> a, eps, 2];N[Det[a + eps] - t1, 20]d2 = D[d1, m]t2 = t1 + 1 / 2ArrayDot[ArrayDot[Normal[d2 /. m -> a], eps, 2], eps, 2];N[Det[a + eps] - t2, 20]Derive a least-squares solution for data
given as a list of pairs
:
m = MatrixSymbol["m", {n, 2}]Find the vector of vertical deviations
for the data:
dev = m.{-a, 1} - bDefine the sum of squares of the vertical deviations for the data:
squareDeviations = dev.devSet up the least-squares equations:
eqna = D[squareDeviations, a] == 0eqnb = D[squareDeviations, b] == 0n = 200;data = Table[{x, 3x + 20 + RandomReal[{-15, 15}]}, {x, 1, n}];Solve the least-squares problem for this data:
a x + b /. Solve[Normal[{eqna, eqnb}] /. m -> data, {a, b}][[1]]Show[{ListPlot[data], Plot[%, {x, 0, 200}, PlotStyle -> Red]}]Find an optimality condition for a portfolio optimization problem with the expected return
and standard deviation
:
x = VectorSymbol["x", n];
μ = VectorSymbol["μ", n];
Σ = MatrixSymbol["Σ", {n, n}];
Subscript[μ, p] = μ.x;
Subscript[σ, p] = Sqrt[x.Σ.x];The goal is to maximize
when the vector
of asset weights satisfies Total[x]=1. The constraint can be used to represent
where the unconstrained vector variable
consists of the first
coordinates of
:
A = MatrixSymbol["A", {n, n - 1}];
y = VectorSymbol["y", n - 1];
b = UnitVector[n, n];The maximum occurs at a critical point of
:
cond = D[Subscript[μ, p] / Subscript[σ, p] /. x -> A.y + b, y] == 0Express the condition in terms of
:
cond /. A.y + b -> xCompute the gradient of the log-likelihood function of the linear regression model represented by the equation
, where
are normally distributed random variables with mean zero and variance
:
y = VectorSymbol["y", n];
X = MatrixSymbol["X", {n, k}];
β = VectorSymbol["β", k];
u = VectorSymbol["u", n];The log-likelihood function
is given by:
l = -n / 2Log[σsquared] - 1 / (2σsquared)u.uSubscript[l, β] = D[l /. u -> y - X.β, β]Express the result in terms of
:
Subscript[l, β] /. y - X.β -> uSubscript[l, σ^2] = D[l, σsquared]Properties & Relations (4)
A matrix symbol is a tensor of rank 2:
TensorRank[MatrixSymbol["a"]]Use TensorDimensions to get the dimensions of a matrix symbol:
TensorDimensions[MatrixSymbol["a", {m, n}]]MatrixSymbol["name"] represents a matrix of unknown dimensions:
TensorDimensions[MatrixSymbol["a"]]Use TensorSymmetry to get the symmetry of a matrix symbol:
TensorSymmetry[MatrixSymbol["a", {n, n}, Reals, Symmetric[{1, 2}]]]By default, no symmetry is assumed:
TensorSymmetry[MatrixSymbol["a", {n, n}]]ArraySymbol[a,{m,n}] and MatrixSymbol[a,{m,n}] both represent matrices:
TensorDimensions[MatrixSymbol["a", {m, n}]] == TensorDimensions[ArraySymbol["a", {m, n}]]However, MatrixSymbol[a,m] represents a square matrix:
TensorDimensions[MatrixSymbol["a", m]]Whereas ArraySymbol[a,m] represents a vector:
TensorDimensions[ArraySymbol["a", m]]Related Guides
History
Text
Wolfram Research (2024), MatrixSymbol, Wolfram Language function, https://reference.wolfram.com/language/ref/MatrixSymbol.html.
CMS
Wolfram Language. 2024. "MatrixSymbol." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/MatrixSymbol.html.
APA
Wolfram Language. (2024). MatrixSymbol. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MatrixSymbol.html
BibTeX
@misc{reference.wolfram_2026_matrixsymbol, author="Wolfram Research", title="{MatrixSymbol}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/MatrixSymbol.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_matrixsymbol, organization={Wolfram Research}, title={MatrixSymbol}, year={2024}, url={https://reference.wolfram.com/language/ref/MatrixSymbol.html}, note=[Accessed: 12-June-2026]}