PRODUCTS
Products Overview
Mathematica
Mathematica Student Edition
Mathematica Home Edition
Wolfram
CDF Player
(free download)
Computable Document Format (CDF)
web
Mathematica
grid
Mathematica
Wolfram
Workbench
Wolfram
SystemModeler
Wolfram
Finance Platform
Mathematica
Add-Ons
Wolfram|Alpha Products
SOLUTIONS
Solutions Overview
Engineering
Aerospace Engineering & Defense
Chemical Engineering
Control Systems
Electrical Engineering
Image Processing
Industrial Engineering
Materials Science
Mechanical Engineering
Operations Research
Optics
Petroleum Engineering
Biotechnology & Medicine
Bioinformatics
Medical Imaging
Finance, Statistics & Business Analysis
Actuarial Sciences
Data Analysis & Mining
Econometrics
Economics
Financial Engineering & Mathematics
Financial Risk Management
Statistics
Software Engineering & Content Delivery
Authoring & Publishing
Interface Development
Software Engineering
Web Development
Science
Astronomy
Biological Sciences
Chemistry
Environmental Sciences
Geosciences
Social & Behavioral Sciences
Design, Arts & Entertainment
Game Design, Special Effects & Generative Art
Education
STEM Education Initiative
Higher Education
Community & Technical College Education
Primary & Secondary Education
Students
Technology
Computable Document Format (CDF)
High-Performance & Parallel Computing (HPC)
See Also: Technology Guide
PURCHASE
Online Store
Other Ways to Buy
Volume & Site Licensing
Contact Sales
Software
Service
Upgrades
Training
Books
Merchandise
SUPPORT
Support Overview
Mathematica
Documentation
Knowledge Base
Learning Center
Technical Services
Community & Forums
Training
Does My Site Have a License?
Wolfram User Portal
COMPANY
About Wolfram Research
News
Events
Wolfram Blog
Partnerships
Employment Opportunities
History of
Mathematica
Stephen Wolfram's Home Page
Contact Us
OUR SITES
All Sites
Wolfram|Alpha
Demonstrations Project
MathWorld
Integrator
Wolfram Functions Site
Mathematica Journal
Wolfram Media
Wolfram
Tones
Wolfram Science
Stephen Wolfram
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE
DOCUMENTATION CENTER
FOR THE LATEST INFORMATION.
DOCUMENTATION CENTER SEARCH
New to
Mathematica
?
Find your learning path
»
Mathematica
>
Mathematics and Algorithms
>
Matrices and Linear Algebra
>
Constructing Matrices
>
DiagonalMatrix
>
Mathematica
>
Mathematics and Algorithms
>
Graphs & Networks
>
Graph Programming
>
Matrices and Linear Algebra
>
Constructing Matrices
>
DiagonalMatrix
>
Mathematica
>
Visualization and Graphics
>
Graphs & Networks
>
Graph Programming
>
Matrices and Linear Algebra
>
Constructing Matrices
>
DiagonalMatrix
>
BUILT-IN MATHEMATICA SYMBOL
Vectors and Matrices
Constructing Matrices
Tutorials »
|
IdentityMatrix
Diagonal
Tr
KroneckerDelta
Band
See Also »
|
Constructing Matrices
Matrices and Linear Algebra
Structure Matrices & Convolution Kernels
Summary of New Features in 7.0
New in 6.0: Matrix & Linear Algebra Functions
New in 7.0: Lists and Matrices
More About »
DiagonalMatrix
DiagonalMatrix
[
list
]
gives a matrix with the elements of
list
on the leading diagonal, and
elsewhere.
DiagonalMatrix
gives a matrix with the elements of
list
on the
k
diagonal.
DiagonalMatrix
pads with
s to create an
n
×
n
matrix.
MORE INFORMATION
For positive
k
,
DiagonalMatrix
puts the elements
k
positions above the main diagonal.
DiagonalMatrix
puts the elements
k
positions below.
DiagonalMatrix
fills the
k
diagonal of a square matrix with the elements from
list
. Different values of
k
lead to different matrix dimensions.
DiagonalMatrix
always creates an
n
×
n
matrix, even if this requires dropping elements of
list
.
»
DiagonalMatrix
creates an
m
×
n
matrix.
DiagonalMatrix
[
SparseArray
[
...
],
...
]
gives a
SparseArray
object.
EXAMPLES
CLOSE ALL
Basic Examples
(1)
Construct a diagonal matrix:
A superdiagonal matrix:
A subdiagonal matrix:
Construct a diagonal matrix:
In[1]:=
Out[1]//MatrixForm=
A superdiagonal matrix:
In[2]:=
Out[2]//MatrixForm=
A subdiagonal matrix:
In[3]:=
Out[3]//MatrixForm=
Scope
(4)
The elements in
DiagonalMatrix
are chosen to match the elements of the vector:
Exact number entries:
Machine-number entries:
Arbitrary-precision number entries:
When the vector is a
SparseArray
object,
DiagonalMatrix
will give a
SparseArray
object:
Pad with zeros to make a larger square matrix:
Make a square matrix with the specified dimension:
Rectangular diagonal matrices:
Applications
(4)
Express a matrix as the sum of its diagonal and off-diagonal parts:
Verify the similarity of a matrix to the diagonal matrix of its eigenvalues:
Define a Jordan matrix:
Construct a 5×5 tridiagonal matrix:
This can also be done using
Band
:
Properties & Relations
(6)
IdentityMatrix
is a special case of
DiagonalMatrix
:
Several simple properties hold for diagonal matrices:
Inverse
,
MatrixExp
, and
MatrixPower
commute with
DiagonalMatrix
:
Det
and
Tr
have commuting relations:
Diagonal
of
DiagonalMatrix
gives the original vector:
This is true even if the vector is a
SparseArray
object:
Matrices with only subdiagonals or superdiagonals are always nilpotent:
The size of the matrix generated by
DiagonalMatrix
equals
Length
[
list
]+
Abs
[
k
]
:
Band
can be used to construct diagonals equivalent to
DiagonalMatrix
:
They will be
SameQ
if the vector is a
SparseArray
:
SEE ALSO
IdentityMatrix
Diagonal
Tr
KroneckerDelta
Band
TUTORIALS
Vectors and Matrices
Constructing Matrices
MORE ABOUT
Constructing Matrices
Matrices and Linear Algebra
Structure Matrices & Convolution Kernels
Summary of New Features in 7.0
New in 6.0: Matrix & Linear Algebra Functions
New in 7.0: Lists and Matrices
New in 1 | Last modified in 7