Professional Documents
Culture Documents
(pu0) + qu = f,
we need to evaluate the following integrals
Z xR
p0i0j dx,
xL
a < x < b,
xR
qi j dx,
xL
xR
fj dx,
xL
where [xL, xR] represents an element. In general, these integrals shall NOT be pre-evaluated manually and then
programmed in the code. Instead they should be evaluated by a numerical quadrature.
ba
a+b
g(a) + 4g
+ g(b) .
6
2
g(x)dx S[g] =
a
(a, b).
Note that the Simpsons rule provides the exact integral if g(x) is a polynomial of degree 3 or less. Also because
of that prefactor of 1/2880, this method is quite accurate because b a h is small in FEM.
Adaptive Simpsons rule: subdivide [a, b] into multiple subintervals, and then apply the Simpsons rule to
each subinterval. The Matlab built-in quadrature quad() uses Adaptive Simpsons rule.
The Simpsons 3/8 rule: is
Z
=
g(x)dx S[g]
a
ba
2a + b
a + 2b
g(a) + 3g
+ 3g
+ g(b) .
8
3
3
g()d:
1
g()d =
1
N
X
i=1
wig(i ),
(a, b).
where i and wi are called quadrature points and weights. We want to choose i and wi so that the
quadrature is as accurate as possible. In the mid-point rule, the trapezoidal rule, and the Simpsons
methods, i are pre-defined (e.g. as end- and mid-points of the interval). In the Gaussian quadratures,
however, both i and wi are unknowns. Generally we can choose i and wi such that the quadrature
formula is exact for g() = 1, , , 2N 1. The number 2N 1 is called the algebraic precision of the
quadrature formula. Such quadrature formulas have the following characteristics:
Very accurate: A Gaussian quadrature using N points can provide the exact integral if g() is a
polynomial of degree 2N 1 or less.
Open formulas: do not need to use two end points. (Otherwise, use Gauss-Radau or Gauss-Lobatto
quadrature)
No recursive relations for i and wi.
Good for finite element methods because b a h is small; we just need a few points i .
We call i and wi Gaussian points and weights of the quadrature formulas.
(b) Gaussian quadrature of order 1 (one point):
Z
g()d = w1g(1 ).
1
1
Z 1
g()d = 0
0 = w1 1 ,
w1 = 2,
1 = 0.
1
1
g()d = 0
1
Z 1
g()d =
1
1
2
3
g()d = 0
0 = w11 + w2 2 ,
2
= w112 + w2 22,
3
0 = w113 + w2 23.
w1 = w2 = 1,
2
1
2 = .
3
!
3
.
5
f(x)dx:
a
f(x)dx =
a
f()d
1
xa xb
ba
+
, or x = a +
(1 + )
ba
ba
2
2
ba
d =
dx, dx =
d.
ba
2
Z b
Z
ba 1
ba
f(x)dx =
f a+
(1 + ) d.
2
2
a
1
=
Therefore, we have
b
a
ba X
f(x)dx
wi f
2
N
i=1
ba
a+
(1 + i ) .
2
is int f.m. It uses f.m which defines the function f(x) and GaussPoints.m which provides Gaussian points
and weights. The calling sequence of int f.m is
int_f(quadrature_order, lower_limit_a, upper_limit_b)
A simple test: Consider the following integral
Z 1
I=
x9 + x4 + 2x + 1 = 2.3
0
Since f(x) = x9 + x4 + 2x + 1 has degree of 9, Gaussian quadrature with N = 5 should be able to provide the
exact integral. Actually we have
(i) int f(4, 0, 1) returns 2.299897959183662, which is close to the exact one but definitely not exact!
(ii) int f(5, 0, 1) returns the exact value 2.3.
(iii) int f(6, 0, 1) returns the exact value 2.3.
function y = int_f(N,a,b)
%
%
function y = f(x)
y = x^9+x^4+2*x+1;
return
function xw = GaussPoints(n)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
Function GaussPoints provides the Gaussian points x(i) and weights %
%
w(i) for the Gaussian quadrature of order n.
%
%
%
%
Input: n
- the order of the Gaussian quadrature
%
%
%
%
Output: xw - a n by 2 matrix: First column gives the points
%
%
Second column gives the weights
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
xw = zeros(n,2);
if (n == 1)
xw=[ 0.00000000000000
2.00000000000000];
elseif (n == 2)
xw=[-0.57735026918963
0.57735026918963
1.00000000000000
1.00000000000000];
elseif (n == 3)
xw=[-0.77459666924148
0.00000000000000
0.77459666924148
0.55555555555555
0.88888888888889
0.55555555555555];
elseif (n == 4)
xw=[-0.86113631159405
-0.33998104358486
0.33998104358486
0.86113631159405
0.34785484513745
0.65214515486254
0.65214515486255
0.34785484513745];
elseif (n == 5)
xw=[-0.90617984593866
-0.53846931010568
0.00000000000000
0.53846931010568
0.90617984593866
0.23692688505619
0.47862867049937
0.56888888888889
0.47862867049937
0.23692688505619];
elseif (n == 6)
xw=[-0.93246951420315
-0.66120938646626
-0.23861918608320
0.23861918608320
0.66120938646626
0.93246951420315
0.17132449237917
0.36076157304814
0.46791393457269
0.46791393457269
0.36076157304814
0.17132449237917];
elseif (n == 7)
xw=[-0.94910791234276
-0.74153118559939
-0.40584515137740
0.00000000000000
0.40584515137740
0.74153118559939
0.94910791234276
0.12948496616887
0.27970539148928
0.38183005050512
0.41795918367347
0.38183005050512
0.27970539148928
0.12948496616887];
elseif (n == 8)
xw=[-0.96028985649754
-0.79666647741363
-0.52553240991633
-0.18343464249565
0.18343464249565
0.52553240991633
0.79666647741363
0.96028985649754
0.10122853629038
0.22238103445337
0.31370664587789
0.36268378337836
0.36268378337836
0.31370664587789
0.22238103445337
0.10122853629038];
else
error(Bad input n);
end
return