# Automatic generation of integration points and weights for triangles and tetrahedra

Usually one would consult a paper or book to find integration points and weights for unit triangle and tetrahedra. I am looking for a method to automatically compute such points and weights. The following Mathematica code example computes integration weights and points for unit line (quad/hexahedron) elements:

unitGaussianQuadraturePoints[points_] :=
Sort[x /.
Solve[Evaluate[LegendreP[points, x] == 0], {x}], !
OrderedQ[N[{#1, #2}]] &];

unitGaussianQuadratureWeights[points_] :=
Module[{gps, f, int, integr, vars, eqns},
gps = unitGaussianQuadraturePoints[points];
f[0, 0] := 1;
f[0., 0] := 1.;
f[x_, n_] := x^n;
int = Integrate[f[x, #], x] & /@ Range[0, points - 1];
integr = Subtract @@@ (int /. x :> {1, -1});
vars = Table[Unique[c], {Length[gps]}];
eqns =
Table[Plus @@ Thread[Times[vars, f[#, i - 1] & /@ gps]] ==
integr[[i]], {i, points}];
Return[(vars /. Solve[eqns, vars])];];

unitGaussianQuadratureWeights

{{1, 1}}

unitGaussianQuadraturePoints

{1/Sqrt, -(1/Sqrt)}


I am looking for a paper/book that describes algorithmically how this is done for triangles and/or tetrahedra. Can someone point me to some information about this. Thanks.

• There's an easier way to do your Gauss-Legendre quadrature rules in Mathematica: {points, weights} = MapThread[Map, {{2 # - 1 &, 2 # &}, Most[NIntegrateGaussRuleData[n, prec]]}]. – J. M. Jan 22 '12 at 16:31
• In any event: have you seen this? – J. M. Jan 22 '12 at 16:35
• @J.M, your above proposed method does, unfortunately, not work for prec=Infinity; but thanks for that too. – user530 Jan 22 '12 at 17:47
• In that case, here's a method that works, due to Golub and Welsch: Transpose[MapAt[2(First /@ #)^2 &, Eigensystem[SparseArray[{Band[{2, 1}] -> #, Band[{1, 2}] -> #}, {n, n}]], {2}]] &[Table[k/Sqrt[(2 k - 1)(2 k + 1)], {k, n - 1}]]`. – J. M. Jan 22 '12 at 17:59
• Here is the paper by Golub and Welsch. I'll dig through my papers and see if there's something for simplices... – J. M. Jan 22 '12 at 23:14

## 2 Answers

The Encyclopaedia of Cubature Formulas has an extensive list of techniques for this purpose and associated references.

Here is a paper http://journal.library.iisc.ernet.in/vol200405/paper6/rathod.pdf that describes how to map the unit triangle to the standard 2-square in order to calculate the weights and sampling points for the triangle in terms of Gauss-Legendre points for the standard 2-square.

• That's an interesting idea, it looks like for n=2 this needs 4 points, for the typical literature reference for triangles for n=2, 3 points are given. Do you know anything about this? – user530 Jan 22 '12 at 19:31
• This stems from the fact that they are using a mapping from the triangle to the square. I can't say anything beyond that since I don't work with triangles (I use quadrilaterals), so I don't know what is usually done in practice. I just found the paper and thought it seemed like a pretty straightforward thing to do. – James Custer Jan 22 '12 at 19:36
• indeed it is quite straightforward and I'll see that the other papers suggest, but the simplicity for this one and the elegance of using something I already have are a plus for this one. The downside is then the additional function evaluation. Thanks in any case. – user530 Jan 22 '12 at 19:42
• another down side is that the points are not symmetrical. – user530 Jan 24 '12 at 13:19