Graph

Creates new graph

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

Graph(V, E, <VertexWeights = vw>, <EdgeDescriptions = ed>, <EdgeWeights = ew>, <EdgeCosts = ec>, <Directed | Undirected>)

Description

Graph(V, E) creates a graph.

Graph([v1,...,vn],[e1,...,em]) generates a new undirected graph with n vertices and m edges.

Graph([1,a,3], [[1,a],[1,3]], Directed) generates a new directed graph with the vertices 1, a, 3 and the edges [1,a], [1,3].

Graph([a,b,3], [[a,b],[b,3]], VertexWeights = [1,2,3], EdgeWeights = [4,5]) generates a new directed graph where the vertices have the values a=1, b=2, 3=3 and the edges [a,b]=4, [b,3]=5.

Graph([a,b,3], [[a,b],[b,3]], VertexWeights = [1,None,3], EdgeWeights = [4, None]) generates a new directed graph where the vertices have the values a=1, 3=3 and the edges [a,b]=4. The difference to the example directly above is that the keyword None can be used to not assign a value to a vertex or edge.

Examples

Example 1

An (undirected) graph with four vertices:

G1 := Graph([1,a,3], [[1,a],[1,3]]):
Graph::printGraphInformation(G1)
Vertices: [1, 3, a]
Edges: [[1, 3], [1, a], [3, 1], [a, 1]]
Vertex weights: no vertex weights.
Edge descriptions: no edge descriptions.
Edge weights: no edge weights.
Edge costs: no edge costs.
Adjacency list (out): 1 = [3, a], a = [1], 3 = [1]
Adjacency list (in): 1 = [3, a], a = [1], 3 = [1]
Graph is undirected.

Example 2

The same graph but this time with parameter Directed:

G1 := Graph([1,a,3], [[1,a],[1,3]], Directed):
Graph::printGraphInformation(G1)
Vertices: [1, 3, a]
Edges: [[1, 3], [1, a]]
Vertex weights: no vertex weights.
Edge descriptions: no edge descriptions.
Edge weights: no edge weights.
Edge costs: no edge costs.
Adjacency list (out): 1 = [3, a], a = [], 3 = []
Adjacency list (in): 1 = [], a = [1], 3 = [1]
Graph is directed.

Example 3

The circle graph with predefined vertices:

G3 := Graph([a,b,3], [[a,b],[b,3]],
           VertexWeights = [1,2,3],
               EdgeWeights = [4,5]):
Graph::printGraphInformation(G3)
Vertices: [3, a, b]
Edges: [[3, b], [a, b], [b, 3], [b, a]]
Vertex weights: a = 1, b = 2, 3 = 3 (other existing vertices have no weight)
Edge descriptions: no edge descriptions.
Edge weights: [a, b] = 4, [b, 3] = 5, [b, a] = 4, [3, b] = 5 (other existing edges have no weight)
Edge costs: no edge costs.
Adjacency list (out): a = [b], b = [3, a], 3 = [b]
Adjacency list (in): a = [b], b = [3, a], 3 = [b]
Graph is undirected.

Example 4

The circle graph with predefined vertices:

G3 := Graph([a,b,3,7], [[a,b],[b,3],[3,7]], 
VertexWeights = [1,2,3,4], EdgeWeights = [-1,-2,-5], 
EdgeDescriptions = ["Small", None, "Smallest"]):
Graph::printGraphInformation(G3)
Vertices: [3, 7, a, b]
Edges: [[3, 7], [3, b], [7, 3], [a, b], [b, 3], [b, a]]
Vertex weights: a = 1, b = 2, 3 = 3, 7 = 4 (other existing vertices have no weight)
Edge descriptions: [a, b] = "Small", [3, 7] = "Smallest", [b, a] = "Small", [7, 3] = "Smallest"
Edge weights: [a, b] = -1, [b, 3] = -2, [3, 7] = -5, [b, a] = -1, [3, b] = -2, [7, 3] = -5 (other existing edges have n\
o weight)
Edge costs: no edge costs.
Adjacency list (out): a = [b], b = [3, a], 3 = [7, b], 7 = [3]
Adjacency list (in): a = [b], b = [3, a], 3 = [7, b], 7 = [3]
Graph is undirected.

If you look at the edge descriptions, the keyword None can be used for every edge which is not supposed to have a description.

Parameters

V

List of vertices

E

List of edges

vw, ew, ec

List of numbers

ed

List of strings

Options

Directed

The Graph is created as a directed graph.

Undirected

The Graph is created as an undirected graph. Default.

Was this topic helpful?