Upload
did91
View
10
Download
2
Embed Size (px)
DESCRIPTION
math 3
Citation preview
ENGINEERING MATHEMATICS 4ENGINEERING MATHEMATICS 4(BWM 30603 / BDA34003)
Lecture Module 6: Numerical Integration
Waluyo Adi SiswantoUniversiti Tun Hussein Onn Malaysia
This work is licensed under a Creative Commons Attribution 3.0 License.
http://creativecommons.org/licenses/by/3.0/http://creativecommons.org/licenses/by/3.0/
Lecture Module 6 Engineering Mathematics IV 2
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 3
x
yy (x)
x1 xn
You want to calculatethe yellow area,under the curve y(x)
Then you can calculatethe area
Area=x1
xn
y (x)dx
Lecture Module 6 Engineering Mathematics IV 4
x
y
y (x)
x1 xn
If the function is difficultYou will find it difficult to integrate.
Then you can predictby approximation
Area=Area1+Area 2+Area 3
Area=h y1+h y2+h yn1
Or you can write
Area=h ( y1+ y2+ yn1)
Of course not accurate.If you use smaller division ? smaller division ?
y1
y2
yn1
Lecture Module 6 Engineering Mathematics IV 5
Rectangular rule
x
y
y1
x1
y2
y (x)
h
xn
If you want to divide by N division
h=xnx1N
x1
xn
y (x)dx = h( y1+ y2++ yn1)
h
yn1
h
Number of data n= N+1
Lecture Module 6 Engineering Mathematics IV 6
Trapezoidal rule
x
y
y1
x1
y2
y (x)
h
xn
If you want to divide by N division
h=x nx1N
h
yn1
h
x1
xn
y(x)dx = h2( y1+ y2)+
h2( y2+ y3)++
h2( y n1+ yn)
Now the area is not rectangularbut trapezoidaltrapezoidal
x1
xn
y (x)dx = h2( y1+2 y2++2 yn1+ yn)
y3
yn
Lecture Module 6 Engineering Mathematics IV 7
Trapezoidal m function (trapezoidal.m):
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);endI = I + g(b);I = I*h/2;
Lecture Module 6 Engineering Mathematics IV 8
Simpson's rule
Simpson 1/3
x1
xn
y( x)dx = h3( y1+4 y2+2 y3+4 y4+2 y5++4 yn1+ yn)
Simpson 3/8
x1
xn
y( x)dx = 3h8( y1+3( y2+ y3+ y5+ y6+)+2( y4+ y7+)+ yn)
The number of division must be multiplication of 2
The number of division must be multiplication of 3
Lecture Module 6 Engineering Mathematics IV 9
Simpson 1/3 m function (simpson13.m):function I = simpson13(f_str, a, b, n)%SIMPRULE Simpson's rule integration.% I = SIMPRULE(F_STR, A, B, N) returns the Simpson's rule approximation% for the integral of f(x) from x=A to x=B, using N subintervals, where% F_STR is the string representation of f.% An error is generated if N is not a positive, even integer.I=0;g = inline(f_str);h = (b-a)/n;
if((n > 0) && (rem(n,2) == 0)) I = I + g(a); for ii = (a+h):2*h:(b-h) I = I + 4*g(ii); end for kk = (a+2*h):2*h:(b-2*h) I = I + 2*g(kk); end I = I + g(b);
I = I*h/3;else disp('Incorrect Value for N')end
Lecture Module 6 Engineering Mathematics IV 10
Simpson 3/8 m function (simpson38.m):
function int=simpson38(f_str,x1,x2,n)h=(x2-x1)/n;x(1)=x1;f=inline(f_str);
if((n > 0) && (rem(n,3) == 0)) sum=f(x1); for i=2:n x(i)=x(i-1)+h; end for j=2:3:n sum=sum+3*f(x(j)); end for k=3:3:n sum=sum+3*f(x(k)); end for l=4:3:n sum=sum+2*f(x(l)); end sum=sum+f(x2); int=sum*3*h/8;else disp('Incorrect Value for N')end
Lecture Module 6 Engineering Mathematics IV 11
Example 6-1
Find the approximate value of
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
1
4 x x+1
dx
Lecture Module 6 Engineering Mathematics IV 12
Exact integration in SMath
Rectangular rule
N = 12h = 0.25
No data x x/sqrt(x+1)1 1 0.707112 1.25 0.833333 1.5 0.948684 1.75 1.055295 2 1.154706 2.25 1.248087 2.5 1.336318 2.75 1.420099 3 1.5000010 3.25 1.5764811 3.5 1.6499212 3.75 1.7206213 4
15.15060 Result=0.25(15.15060)=3.78765
Lecture Module 6 Engineering Mathematics IV 13
Trapezoidal rule
N = 12h = 0.25
No data x x/sqrt(x+1)1 1 0.707112 1.25 0.833333 1.5 0.948684 1.75 1.055295 2 1.154706 2.25 1.248087 2.5 1.336318 2.75 1.420099 3 1.5000010 3.25 1.5764811 3.5 1.6499212 3.75 1.7206213 4 1.78885
2.49596 14.44350
Result=0.252
(2.49596+2(14.44350))=3.9229
In FreeMat:
Lecture Module 6 Engineering Mathematics IV 14
Simpson 1/3 ruleN = 12h = 0.25
No data x x/sqrt(x+1)1 1 0.707112 1.25 0.833333 1.5 0.948684 1.75 1.055295 2 1.154706 2.25 1.248087 2.5 1.336318 2.75 1.420099 3 1.5000010 3.25 1.5764811 3.5 1.6499212 3.75 1.7206213 4 1.78885
2.49596 7.85389 6.58961
Result=0.253
(2.49596+4(7.85389)+2(6.48961))=3.9242
In FreeMat :
Lecture Module 6 Engineering Mathematics IV 15
Simpson 3/8 rule
N = 12h = 0.25
No data x x/sqrt(x+1)1 1 0.707112 1.25 0.833333 1.5 0.948684 1.75 1.055295 2 1.154706 2.25 1.248087 2.5 1.336318 2.75 1.420099 3 1.5000010 3.25 1.5764811 3.5 1.6499212 3.75 1.7206213 4 1.78885
2.49596 10.47542 3.96808
Result=(3)0.258
(2.49596+3(10.47542)+2(3.96808))=3.9242
In FreeMat :
Lecture Module 6 Engineering Mathematics IV 16
Example 6-2A 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.
0 2 4 6 8 10 120
20
40
60
80
100
120
140
160
180
0
5060
7075
8090
110
150160
170 170 170
time (seconds)
spee
d (k
m/h
)
Lecture Module 6 Engineering Mathematics IV 17
N = 12h= 1/3600
no t v(t)1 0 02 1 503 2 604 3 705 4 756 5 807 6 908 7 1109 8 15010 9 16011 10 17012 11 17013 12 170
170 640 545
Result= 133600
(170+4(640)+2(545))=0.3537 km
Lecture Module 6 Engineering Mathematics IV 18
Gauss QuadratureThe main idea in Gauss QuadratureGauss Quadrature is to change the integration limits tonatural (dimensionless) coordinate limits from -1 to 1
x
y y (x)
x1 xn
()
1 1
Change tonaturalcoordinates
Lecture Module 6 Engineering Mathematics IV 19
Gauss QuadratureThe main idea in Gauss QuadratureGauss Quadrature is to change the integration limits tonatural (dimensionless) coordinate limits from -1 to 1
x
y y (x)
x1 xn
()
1 1
I=xnx1
2 11
()d
x=12 [(1) x1+(1+) xn ]
()= y (x)
I=xnx1
2I
Lecture Module 6 Engineering Mathematics IV 20
I =1
1
()d
I = R1(1) + R2(2) ++ Rn(n)
j is the location of the integration point j relative to the center
R j is the weighting factor for point j relative to the center,and n is the number of points at which is to be calculated()
Lecture Module 6 Engineering Mathematics IV 21
Gauss QuadratureCoefficients for Gaussian Quadrature
jn R j
1 0.0 2.0
2 0.5773502692 1.0
3 0.7745966692 0.5555555560.0 0.888888889
4 0.8611363116 0.34785484510.3399810436 0.6521451549
5 0.9061798459 0.23692688510.5384693101 0.4786286705
0.0 0.5688888889
Lecture Module 6 Engineering Mathematics IV 22
Program to generate abscissa and weight for any number of integration pointsfunction [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; endA = 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; endend
Lecture Module 6 Engineering Mathematics IV 23
Program to use Gauss Quadrature, any number of integration points
function I = GaussQuadrature(func,a,b,n)% USAGE: I = gaussQuad(func,a,b,n)% func = handle of function to be integrated.% for example --> func= @(x) ((sin(x)/x)^2)% a,b = integration limits.% n = order of integration points% I = integral resultformat long;c1 = (b + a)/2; c2 = (b - a)/2;[x,A] = GaussNodes(n); sum = 0;for i = 1:length(x) y = feval(func,c1 + c2*x(i)); sum = sum + A(i)*y;endI = c2*sum;
Lecture Module 6 Engineering Mathematics IV 24
()
1 1
Gauss Quadrature1 point
weighting2.0
I = R1(1)
0.0
I = 2.0 (0)
Lecture Module 6 Engineering Mathematics IV 25
()
1 1
Gauss Quadrature2 points
weighting1.0
I = R1(1) + R2(2)
I = 1.0 (0.5773502692) + 1.0 (0.5773502692)
0.57
7350
2692
1.0
-0.5
7735
0269
2
0.0
Lecture Module 6 Engineering Mathematics IV 26
()
1 1
Gauss Quadrature3 points
weighting
I = R1(1) + R2(2) + R3(3)
I = 0.555555556 (0.7745966692) +0.888888889 (0.0) +0.555555556 (0.7745966692)
0.77
4596
6692
-0.7
7459
6669
2
0.0
0.8888888890.5555555560.555555556
Lecture Module 6 Engineering Mathematics IV 27
Example 6-3
Find the approximate value of
By using :
a) Gauss Quadrature 2 points
b) Gauss Quadrature 3 points
1
4 x x+1
dx
Lecture Module 6 Engineering Mathematics IV 28
Lecture Module 6 Engineering Mathematics IV 29
Lecture Module 6 Engineering Mathematics IV 30
Example 6-4
Find the approximate value of
By using :
a) Gauss Quadrature 4 points
b) Check your result in Smath (Exact integration)
c) Check your result, using Freemat (GaussQuadrature)
1
41+x2
x3+1dx
Lecture Module 6 Engineering Mathematics IV 31
Lecture Module 6 Engineering Mathematics IV 32
Lecture Module 6 Engineering Mathematics IV 33
Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33