PRODUCTS
Products Overview
Mathematica
Mathematica for Students
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
Knowledge Base
Learning Center
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
DOCUMENTATION CENTER SEARCH
New to
Mathematica
?
Find your learning path
»
Mathematica
>
BUILT-IN MATHEMATICA SYMBOL
GraphDistance
AdjacencyMatrix
GraphPower
GraphRadius
GraphDiameter
GraphCenter
GraphPeriphery
See Also »
|
Graph Measures & Metrics
Paths and Cycles
New in 8.0: Alphabetical Listing
More About »
GraphDistanceMatrix
GraphDistanceMatrix
[
g
]
gives the matrix of distances between vertices for the graph
g
.
GraphDistanceMatrix
gives the matrix of distances between vertices of maximal distance
d
in the graph
g
.
MORE INFORMATION
GraphDistanceMatrix
returns a
SparseArray
object or an ordinary matrix.
The entries of the distance matrix
give the shortest distance from vertex
to vertex
.
The diagonal entries
of the distance matrix are always zero.
The entry
is
Infinity
(
) if there is no path from vertex
to vertex
.
In
GraphDistanceMatrix
, an entry
will be
Infinity
if there is no path from vertex
to vertex
in
d
steps or less.
The vertices
are assumed to be in the order given by
VertexList
[
g
]
.
EXAMPLES
CLOSE ALL
Basic Examples
(1)
Give the matrix of distances for a complete graph:
Give the matrix of distances for a complete graph:
In[1]:=
Out[1]=
In[2]:=
Out[2]//MatrixForm=
Scope
(5)
GraphDistanceMatrix
works with undirected graphs:
Directed graphs:
Weighted graphs:
Extract a single matrix column for a graph of modest size:
Using
GraphDistance
to compute the same result takes more time:
Works with large graphs:
When just a single column is needed and the graph is large, using
GraphDistance
is faster:
Options
(6)
The method is automatically chosen depending on input:
method will use the weight 1 for every edge:
can be used for graphs with positive edge weights only:
can be used for directed graphs including negative edge weights:
can be used for directed graphs including negative edge weights:
can be faster than the
method on sparse graphs:
Applications
(2)
Find the vertex eccentricity, taking the entire graph into account:
For the strongly connected graph, the result is in agreement with
VertexEccentricity
:
Find the vertex eccentricity of every vertex in a connected graph:
Check the result:
Properties & Relations
(5)
Rows and columns of the distance matrix follow the order given by
VertexList
:
The diagonal entries of the distance matrix are always zero:
The distance matrix can be found using
GraphDistance
:
In a connected graph, the
VertexEccentricity
can be obtained from the distance matrix:
The distance between two vertices belonging to different connected components is
Infinity
:
Possible Issues
(2)
The matrix indices may not have the expected correspondence to vertices:
The distance from
to
is not at the expected matrix position:
The reason is that vertices are not in the expected order:
Solve the problem by listing vertices explicitly when calling functions such as
Graph
:
Now the distance is found at the expected position:
is not a valid
Method
option:
Use
,
, or the default choice of
Method
instead:
Neat Examples
(1)
SEE ALSO
GraphDistance
AdjacencyMatrix
GraphPower
GraphRadius
GraphDiameter
GraphCenter
GraphPeriphery
MORE ABOUT
Graph Measures & Metrics
Paths and Cycles
New in 8.0: Alphabetical Listing
New in 8