Computing Homology

MATH 348 Topology

Computing boundary matrices of a simplicial complex

The following function computes the boundary matrix for a given simplicial complex in the specified dimension. The simplicial complex must be supplied as a MeshRegion.

boundaryMatrix[complex_,dimension_]:=Module[
(* local variables *)
{simplices, faces,matrix, row, col},

(* get lists of simplices of the appropriate dimensions *)
simplices=MeshCells[complex,dimension];
faces=Table[If[dimension==1,{face[[1]]},Sort[face[[1]]]],{face,MeshCells[complex,dimension-1]}];

(* initialize a zero matrix *)
matrix=Table[0,Length[faces],Length[simplices]];

(* set entries in the matrix *)
col=1;
Do[
Do[
row=Position[faces,Sort[r]][[1,1]];
matrix[[row,col]]=1,
{r,Subsets[simp[[1]],{dimension}]}];
col+=1
,
{simp, simplices}];

(* return the matrix *)
matrix
]

Worksheet example

Here is the simplicial complex from the worksheet.

complex=MeshRegion[{{0,0},{1.9,-0.1},{1.7,1.5},{0.2,1.6},{-2,0.5},{1,-1.3},{4,0.7},{0.7,2.8}}, {Triangle[{1,2,6}],Triangle[{1,4,5}],Triangle[{1,5,6}],Triangle[{2,6,7}],Triangle[{2,3,7}],Triangle[{3,7,8}],Triangle[{3,4,8}],Triangle[{4,5,8}]}]

Sphere example

sphere=ConvexHullMesh[SpherePoints[50]]

Torus example

torus=TriangulateMesh[DiscretizeRegion[Torus[]]]