Code covered by the BSD License  

Highlights from
Matgraph

from Matgraph by Ed Scheinerman
Toolbox for working with simple, undirected graphs

Description of cube
Home > matgraph > @graph > cube.m

cube

PURPOSE ^

cube(g,k) --- create a k-cube (default k = 3)

SYNOPSIS ^

function cube(g,k)

DESCRIPTION ^

 cube(g,k) --- create a k-cube (default k = 3)

CROSS-REFERENCE INFORMATION ^

This function calls:
  • add add --- add edge(s) to the graph
  • cartesian cartesian(g,h1,h2) --- overwrite g with the product of h1 and h2
  • clear_edges clear_edges(g) --- delete all edges of g
  • complete complete: build complete and complete multipartite graphs
  • copy copy(g,h) --- overwrite g with a copy of h
  • cube cube(g,k) --- create a k-cube (default k = 3)
  • embed embed --- create an embedding for a graph
  • free free(g) --- free the graph from the system
  • full full(g) --- convert internal storage for g to full
  • graph graph: constructor for the graph class
  • path path(g,n) --- make g a path on n vertices
  • resize resize(g,n) --- change the number of vertices in g to n
This function is called by:
  • cube cube(g,k) --- create a k-cube (default k = 3)

SOURCE CODE ^

0001 function cube(g,k)
0002 % cube(g,k) --- create a k-cube (default k = 3)
0003 
0004 if nargin==1
0005     cube(g,3);
0006     xy = [ 
0007         0   0
0008         1   0
0009         0   1  
0010         1   1
0011         ];
0012     xy = [xy ; 2*xy-1/2];
0013     embed(g,xy);
0014     return
0015         
0016 end
0017 
0018 if (k==1)
0019     path(g,2);
0020     return
0021 end
0022 
0023 if (k==2)
0024     resize(g,4);
0025     clear_edges(g);
0026     full(g);
0027     elist = [ 1 2; 2 4; 4 3; 3 1];
0028     add(g,elist);
0029     xy = [ 0 0 ; 1 0 ; 0 1 ; 1 1];
0030     embed(g,xy);
0031     return
0032 end
0033 
0034 cube(g,k-1);
0035 
0036 k2 = graph(2);
0037 tmp = graph;
0038 
0039 complete(k2);
0040 embed(k2,[-1,0;1,0]);
0041 copy(tmp,g);
0042 cartesian(g,tmp,k2);
0043 
0044 free(k2);
0045 free(tmp);

Generated on Thu 13-Mar-2008 14:23:52 by m2html © 2003

Contact us at files@mathworks.com