Modelling and Computer
Analysis for Engineers
Lectures 29 & 30:
Gaussian quadrature
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA) 1
Content
• Definition of Gaussian quadrature
• Computation of weights and points for 2point
Gaussian quadrature
• Change of interval for Gaussian quadrature
• Ways of increasing integration accuracy
• Multidimensional integrals
• Real life example of usage
• Improper integrals
2
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
Definition:
• A quadrature rule is an approximation of the definite integral
of a function, usually stated as a weighted sum of function
values at specified points within the domain of integration
• The numerical integration algorithms presented so far
(Trapezoidal rule, Simpson’s rule) worked on evenly spaced
points
• Trapezoidal rule:
• w
i
– weight factors, x
i
– evaluation points
3
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
(1)
1
}
¿
=
· ~
b
a
n
i
i i
) f(x w f(x)dx
• Carl Friedrich Gauss (German mathematician
and scientist) noticed that by suitable
choosing both the weights and the evaluation
points the accuracy of the integral can be
improved
• He proposed to choose the weights and points
so that the procedure should be exact for
polynomials of a degree as high as possible
• If the procedure requires the evaluation of the
function in n points, it has 2n parameters to
be determined (w
i
and x
i
, i = 1 … n) (see eq. 1)
4
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
• Because a general polynomial of degree N has
N+1 coefficients, the Gaussian quadrature
with n points is required to be exact for any
polynomial of degree N = 2n1 (which also
have 2n parameters) or less
• The Gaussian quadrature algorithms are
conventionally stated for the integration
domain [1, 1], with symmetrical weights and
points:
5
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
(2)
2
1
, odd for ] [
1
1
1
0 0
n
k n ) x f( ) f(x w ) f(x w f(x)dx
k
i
i i i
= ÷ + · + · ~
}
¿
÷
=
(3)
2
, even for ] [
1
1
1
n
k n ) x f( ) f(x w f(x)dx
k
i
i i i
= ÷ + · ~
}
¿
÷
=
Computation of weights and points
for 2point Gaussian quadrature
• n=2, the parameters are w
1
and x
1
according to
eq. 3, and the procedure should be exact for
polynomials of degree up to N = 2n1 = 3
• Any polynomial of degree up to N = 3 can be
written as a linear combination of the following
monomials: 1, x, x
2
, x
3
• If the procedure is exact for any polynomial of
degree up to 3, it has to be exact for the above
monomials as well
6
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
constants  x c x b 1 a
3 2
a,b,c,d x d p(x) · + · + · + · =
• By substituting the 4 monomials in eq. 3:
• Relations (5) and (7) are automatically
satisfied because of the symmetry of weights
and points
• From eq. 4 and 6: w
1
= 1 and x
1
2
= 1/3
7
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
(7) ] [ 0
(6) ] [ 3 / 2
(5) ] [ 0
(4) ] 1 1 [ 2 1
1
1
3
1
3
1 1
3
1
1
2
1
2
1 1
2
1
1
1 1 1
1
1
1
}
}
}
}
÷
÷
÷
÷
÷ · = =
+ · = =
÷ · = =
+ · = =
x x w dx x
x x w dx x
x x w xdx
w dx
• The 2point Gaussian quadrature:
• Although very simple, eq. 8 is exact for
polynomials up to 3
rd
degree!
• If the function that is integrated is not a
polynomial of degree 3 or less, eq. 8 will give
an approximation only – the accuracy depends
on how much the function resembles a
polynomial of 3
rd
degree
8
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
(8) )
3
1
( )
3
1
( ) (
1
1
÷
+ ~
}
÷
f f dx x f
• Example:
– Exact integral:
– Gaussian quadrature:
• The same procedure can be applied to find the
weights and points for higher degree Gaussian
quadratures (n = 3,4,…) – very tedious
• The weights and points are usually given in
tabular form
9
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
}
÷
÷
= ÷ ÷ = =
1
1
1
1
.. 6829 . 1 ) 1 sin( ) 1 sin( ) sin( ) cos( x dx x
1.6758.. )
3
1
cos( )
3
1
cos( ) cos(
1
1
=
÷
+ ~
}
÷
dx x
Change of interval for Gaussian
quadrature
• If the integration interval is not [1, 1], a
change of variable can be used to modify it:
10
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
(11)
2
2
1
1
(10) ,
(9) ) (
¦
¹
¦
´
¦
+
=
÷
=
·
¹
´
¦
+ =
+ ÷ =
·
¹
´
¦
= ¬ =
÷ = ¬ =
· = + · =
=
}
a b
n
a b
m
n m b
n m a
z b x
z a x
dz m dx n z m x
dx x f I
b
a
• From eq. 9  11:
• Example:
11
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
(12)
2
)
2 2
( ) (
1
1
} }
÷
÷
·
+
+
÷
= = dz
a b a b
z
a b
f dx x f I
b
a
quadrature Gaussian  0.5714
2 3 / 1
5 . 0
2 3 / 1
5 . 0
2
5 . 0
2
5 . 0
5 0
1 ) 5 . 1 5 . 0 ( 2
1
1 2
1
; 5 0 ; 5 . 1 5 . 0
5 1
2
5 0
2
2; 1;
e exact valu  5493 . 0 ) 1 2 ln(
2
1
1 2
1
1
1
1
1
1
1
2
1
2
1
2
1
=
+ ÷
+
+
~
+
~
+
=
÷ +
=
÷
= + = + · =
=
+
= = = = =
= ÷ =
÷
}
} } }
}
÷
÷ ÷
dz
z
dz
z
dz .
z
dx
x
dz . dx z n z m x
; .
a b
; n .
ba
m b a
x dx
x
Ways of increasing integration
accuracy
• Increase the number of Gauss points
• Composite Gaussian quadrature – divide the
integration domain into subdomains – the
integral value is the sum of Gaussian
quadratures for each subdomain
• A combination of the above
12
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
Example of Matlab implementation:
function g = gauss10(f_handle,a,b)
%GAUSS10(f_handle,a,b) will integrate the function f_handle
% over the interval a<x<b using a 10 point Gauss quadrature
% approximation. Example of use:
% f = @(x) x.^2 + sin(x); g = gauss10(f,0,1).
%======================================================
x = [0.1488743390;0.4333953941;0.6794095683;...
0.8650633667;0.9739065285];
w = [0.2955242247;0.2692667193;0.2190863625;...
0.1494513492;0.0666713443];
t = .5*(b+a)+.5*(ba)*[x; x];
W = [w; w];
g = sum(W.*f_handle(t))*(ba)/2;
end
13
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
Multidimensional integrals
14
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
• The multidimensional integral is computed as
repeated onedimensional integrals
• This is valid for all numerical integration
methods, not only for Gaussian quadrature
• Numerical integration over more than one
dimension is sometimes described as cubature
• Different integration methods can be applied
in different dimensions (e.g. 2 points Gaussian
integration in one dimension and 1 point
Gaussian integration in another dimension)
15
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
Example: 4point Gaussian quadrature in 2D

.
 +
+
÷
·
÷ +
+
÷
·
÷
+
+
+
÷
·
÷ +
+ ·
÷
+
+
+
+ ·
÷ +
+
÷
·
÷
+
\
 +
+ ·
÷ +
+ ·
÷ ÷
·
÷
~ 
.
 +
+
÷ +
+
÷
·
÷
\

+
+
+
÷ +
+ ·
÷ ÷
·
÷
~ 
.

\
 +
+
÷
·
÷
+
+
+ ·
÷ ÷
~

.

\

÷
·
+
+
÷
~ = =
}
}
} }
} } } }
÷
÷
)
2
3
1
2
,
2
3
1
2
( )
2
3
1
2
,
2
3
1
2
(
)
2
3
1
2
,
2
3
1
2
( )
2
3
1
2
,
2
3
1
2
(
2 2
t )
2 2
,
2
3
1
2
( )
2 2
,
2
3
1
2
(
2 2
y ) ,
2
3
1
2
( ) ,
2
3
1
2
(
2
y
2
) ,
2 2
(
y ) ) , ( ( y ) , (
1
1
1
1
c d c d a b a b
f
c d c d a b a b
f
c d c d a b a b
f
c d c d a b a b
f
c d a b
d
c d
t
c d a b a b
f
c d
t
c d a b a b
f
c d a b
d y
a b a b
f y
a b a b
f
a b
d dz
a b
y
a b
z
a b
f
d dx y x f d dx y x f I
d
c
d
c
d
c
b
a
d
c
b
a
Example of use – The Finite
Element Method:
• The Finite Element method is a numerical
method for solving partial differential equations
or integral equations
• When applied to solid mechanics, it requires
many variables to be integrated over the spatial
domain defining the system. For example, the
stiffness matrix of a system is defined as:
16
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
}
=
V
T
EBdV B K
17
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
• The integration domain is divided in smaller sub
domains – the elements
• The integral over each element is computed
using Gaussian quadrature (usually 1 or 2 points
in each dimension)
¿
}
¿
}
= = =
e
V
e T
e
e
V
T
e
EBdV B K EBdV B K
Improper integrals
• Infinite integration limits
• Integrals of functions with vertical asymptotes
(the function becomes unbounded within the
integration domain)
18
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
• Improper integral on a finite domain:
• Improper integral on an infinite domain:
• Oscillatory improper integral:
• Improper integrals that do not converge:
19
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
2 2
x
1
1
0
1
0
= =
}
x dx
1
1
x
1
1
1
2
=
÷
=
·
·
}
x
dx
2
) (
x
sin(x)
0
0
t
= =
·
·
}
x Si dx
dx dx
} }
·
1
1
0
x
1
x
1
• Improper integrals are difficult to integrate.
• For the case where there is an infinite interval of
integration, one may make a change of variables that
transforms the infinite range of integration into a finite
one.
20
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
integral proper a  e
1
1
e e
1
1
;
1
; 1
1
1 e e
1
0
1
 1
2
0
1
2
1
1

0
x 
2
0
x 
0
x 
dt
t
dt
t
dx
x
t dt
t
 dx
t
x
dx
t
t
}
} }
}
=
=

.

\

÷ · =
+
= = ÷ =
= ÷ =
+ ·
· ·
• Methods such as Gaussian quadrature do not use
the value of the integrand at end points, and
hence integrands that are undefined at end
points can be integrated using such methods.
21
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
8.5570... I 1.9785... I
quadrature Gaussian points 40
7.1954... I 1.9575... I
quadrature Gaussian points 20
ln
1
I 2 2
1
I
2 1
2 1
1
0
1
0
2
1
0
1
0
1
= =
= =
· = = = = = =
} }
(x) dx
x
x dx
x
• For a convergent improper integral we can get
better approximations by using more and more
Gauss points – this is wasteful
• In general, an improper integral is easy to
calculate away from its singularity
• For example, for
we get a similar value using the 20 points Gaussian
quadrature
• We want to use lots of Gauss points near the
singularity but not so many elsewhere
22
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
36754 . 1 2
1
I
1
1 . 0
1
1 . 0
1
= = =
}
x dx
x
An adaptive method of numerical integration:
• Compute the following integrals using one of the
numerical integration methods that uses only
interior points:
• We expect that I≈I
1
+I
2
, and if the equation holds with
reasonable accuracy we accept I
1
+I
2
as the value of
the integral
• If the 2 values are not close enough, we calculate
I
1
+I
2
separately using the same method
23
GENG2140
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA)
dx x f
dx x f
dx x f
b
b a
b a
a
b
a
}
}
}
+
+
=
=
=
2
2
2
1
) ( I
) ( I
) ( I
Thank you!
Created by Grand Roman Joldes, PhD (School of Mechanical Engineering, UWA) 24