Beruflich Dokumente
Kultur Dokumente
Topics
Rectangular rule
Trapezoidal rule
Simpson's rule
Simpson 1/3
Simpson 3/8
Gauss Quadrature
2-point
3-point
Lecture Module 6
Engineering Mathematics IV
y ( x)
xn
Area= y ( x) dx
x1
x1
Lecture Module 6
xn
Engineering Mathematics IV
y n1
y ( x)
y2
Area=h y 1 +h y 2 +h y n1
y1
Area=h( y 1 + y 2 + y n1 )
Of course not accurate.
If you use smaller division ?
x1
Lecture Module 6
xn
Engineering Mathematics IV
Rectangular rule
If you want to divide by N division
y
y ( x)
x n x 1
h=
N
y n1
Number of data n = N +1
y2
y1
xn
y ( x)dx = h( y 1+ y 2+ + y n1)
x1
x1
Lecture Module 6
xn
Engineering Mathematics IV
Trapezoidal rule
If you want to divide by N division
y
y ( x)
yn
yn1
y3
y2
h=
x n x 1
N
y1
xn
x1
Lecture Module 6
x1
xn
Engineering Mathematics IV
function I = trapezoidal(f_str, a, b, n)
%TRAPEZOIDAL Trapezoidal Rule integration.
% I = TRAPEZOIDAL(F_STR, A, B, N) returns the Trapezoidal Rule approximation
% for the integral of f(x) from x=A to x=B, using N divisions (subintervals), where
% F_STR is the string representation of f.
I=0;
g = inline(f_str);
h = (b-a)/n;
I = I + g(a);
for ii = (a+h):h:(b-h)
I = I + 2*g(ii);
end
I = I + g(b);
I = I*h/2;
Lecture Module 6
Engineering Mathematics IV
Simpson's rule
Simpson 1/3
xn
y( x)dx =
x1
h
( y +4 y 2 +2 y 3 +4 y 4 +2 y 5 ++4 y n1 + y n )
3 1
Lecture Module 6
Engineering Mathematics IV
Lecture Module 6
Engineering Mathematics IV
Lecture Module 6
Engineering Mathematics IV
10
Example 6-1
4
x
dx
x+1
1
By using :
a) Exact integration, use SMath
b) Rectangular rule, 12 division
c) Trapezoidal rule, 12 division
d) Simpson 1/3, 12 division
e) Simpson 3/8, 12 division
Lecture Module 6
Engineering Mathematics IV
11
Rectangular rule
N=
h=
No data
1
2
3
4
5
6
7
8
9
10
11
12
13
x
1
1.25
1.5
1.75
2
2.25
2.5
2.75
3
3.25
3.5
3.75
4
12
0.25
x/sqrt(x+1)
0.70711
0.83333
0.94868
1.05529
1.15470
1.24808
1.33631
1.42009
1.50000
1.57648
1.64992
1.72062
15.15060
Lecture Module 6
Engineering Mathematics IV
Result=0.25(15.15060)=3.78765
12
Trapezoidal rule
N=
h=
No data
1
2
3
4
5
6
7
8
9
10
11
12
13
x
1
1.25
1.5
1.75
2
2.25
2.5
2.75
3
3.25
3.5
3.75
4
12
0.25
x/sqrt(x+1)
0.70711
0.83333
0.94868
1.05529
1.15470
1.24808
1.33631
1.42009
1.50000
1.57648
1.64992
1.72062
1.78885
2.49596
14.44350
Result=
Lecture Module 6
In FreeMat:
0.25
(2.49596+2(14.44350))=3.9229
2
Engineering Mathematics IV
13
x
1
1.25
1.5
1.75
2
2.25
2.5
2.75
3
3.25
3.5
3.75
4
12
0.25
x/sqrt(x+1)
0.70711
0.83333
0.94868
1.05529
1.15470
1.24808
1.33631
1.42009
1.50000
1.57648
1.64992
1.72062
1.78885
2.49596
Result=
Lecture Module 6
In FreeMat :
7.85389
6.58961
0.25
(2.49596+4(7.85389)+2(6.48961))=3.9242
3
Engineering Mathematics IV
14
x
1
1.25
1.5
1.75
2
2.25
2.5
2.75
3
3.25
3.5
3.75
4
12
0.25
x/sqrt(x+1)
0.70711
0.83333
0.94868
1.05529
1.15470
1.24808
1.33631
1.42009
1.50000
1.57648
1.64992
1.72062
1.78885
2.49596
Result=
Lecture Module 6
In FreeMat :
10.47542
3.96808
(3)0.25
(2.49596+3(10.47542)+2(3.96808))=3.9242
8
Engineering Mathematics IV
15
Example 6-2
A racing car velocity record from start to 12 seconds is shown below.
You have to calculate the distance of the car from its start position in 12 seconds.
The data is taken every 1 second.
Use Simpson's rule 1/3.
180
170
170
170
160
160
150
140
speed (km/h)
120
110
100
90
80
70
75
80
60
60
50
40
20
0
0
0
10
12
time (seconds)
Lecture Module 6
Engineering Mathematics IV
16
N=
h=
12
1/3600
no
1
2
3
4
5
6
7
8
9
10
11
12
13
t
0
1
2
3
4
5
6
7
8
9
10
11
12
v(t)
0
50
60
70
75
80
90
110
150
160
170
170
170
170
Result=
Lecture Module 6
640
545
1
(170+4(640)+2(545))=0.3537 km
33600
Engineering Mathematics IV
17
Gauss Quadrature
The main idea in Gauss Quadrature is to change the integration limits to
natural (dimensionless) coordinate limits from -1 to 1
y ( x)
x1
xn
()
1
Lecture Module 6
1
Engineering Mathematics IV
Change to
natural
coordinates
18
Gauss Quadrature
The main idea in Gauss Quadrature is to change the integration limits to
natural (dimensionless) coordinate limits from -1 to 1
y ( x)
x =
1
[(1) x 1+(1+) x n ]
2
()= y ( x )
x1
xn
x
1
()
x n x1
I=
() d
2 1
I=
1
Lecture Module 6
1
Engineering Mathematics IV
x n x1
I
2
19
I = () d
1
I = R1 (1 ) + R 2 ( 2 ) + + Rn ( n )
j is the location of the integration point j relative to the center
Lecture Module 6
Engineering Mathematics IV
20
Gauss Quadrature
Rj
0.0
2.0
0.5773502692
1.0
0.7745966692
0.555555556
0.0
0.888888889
0.8611363116
0.3478548451
0.3399810436
0.6521451549
0.9061798459
0.2369268851
0.5384693101
0.4786286705
0.0
0.5688888889
4
5
Lecture Module 6
Engineering Mathematics IV
21
Program to generate abscissa and weight for any number of integration points
function [x,A] = GaussNodes(n,tol)
% USAGE: [x,A] = GaussNodes(n,tol)
% n = order of integration points
% tol = error tolerance (default is 1.0e4*eps).
format long;
if nargin < 2;
tol = 1.0e4*eps;
end
A = zeros(n,1);
x = zeros(n,1);
nRoots = fix(n + 1)/2;
for i = 1:nRoots
t = cos(pi*(i - 0.25)/(n + 0.5));
for j = i: 30
p0 = 1.0; p1 = t;
for k = 1:n-1
p = ((2*k + 1)*t*p1 - k*p0)/(k + 1);
p0 = p1;p1 = p;
end
dp = n *(p0 - t*p1)/(1 - t^2);
dt = -p/dp; t = t + dt;
if abs(dt) < tol
x(i) = t; x(n-i+1) = -t;
A(i) = 2/(1-(t^2))/(dp^2);
A(n-i+1) = A(i);
break
end
end
if nRoots == 1
x(i) =0;
end
end
Lecture Module 6
Engineering Mathematics IV
22
Lecture Module 6
Engineering Mathematics IV
23
Gauss Quadrature
1 point
()
0.0
1
2.0
weighting
I = R1 (1 )
I = 2.0 (0)
Lecture Module 6
Engineering Mathematics IV
24
Gauss Quadrature
2 points
0.0
-0.5773502692
0.5773502692
()
1
1.0
1.0
weighting
I = R1 (1 ) + R 2 ( 2 )
I = 1.0 (0.5773502692) + 1.0 (0.5773502692)
Lecture Module 6
Engineering Mathematics IV
25
Gauss Quadrature
3 points
0.0
-0.7745966692
0.7745966692
()
0.888888889
0.555555556
0.555555556
weighting
I = R1 (1 ) + R 2 ( 2 ) + R3 ( 3 )
I = 0.555555556 (0.7745966692) +
0.888888889 (0.0) +
0.555555556 (0.7745966692)
Lecture Module 6
Engineering Mathematics IV
26
Example 6-3
4
x
dx
x+1
1
By using :
a) Gauss Quadrature 2 points
b) Gauss Quadrature 3 points
Lecture Module 6
Engineering Mathematics IV
27
Lecture Module 6
Engineering Mathematics IV
28
Lecture Module 6
Engineering Mathematics IV
29
Example 6-4
4
1+ x 2
Find the approximate value of
dx
3
1 x +1
By using :
a) Gauss Quadrature 4 points
b) Check your result in Smath (Exact integration)
c) Check your result, using Freemat (GaussQuadrature)
Lecture Module 6
Engineering Mathematics IV
30
Lecture Module 6
Engineering Mathematics IV
31
Lecture Module 6
Engineering Mathematics IV
32
Lecture Module 6
Engineering Mathematics IV
33