Clase 14 Calculo Numerico I
Clase 14 Calculo Numerico I
Clase 14 Calculo Numerico I
b
I f ( x ).dx A
a
Newton-Cotes integration Formulas
Introduction
• The Newton-Cotes formulas are the most common
numerical integration methods.
• They are based on the strategy of replacing a
complicated function with an approximating function
that is easy to integrate.
b b
I f ( x)dx f n ( x)dx
a a
f n ( x) a0 a1 x an 1 x n 1 an x n
1. Trapezoidal Rule
The trapezoidal rule uses a polynomial of the first degree to
replace the function to be integrated.
b b
I f ( x ).dx f
a a
1 ( x ).dx
f ( b) f ( a )
f1 ( x ) a ( x a)
ba
b b
I f ( x ).dx f1 ( x ).dx
a a
f ( b) f ( a )
b
a ( x a ) .dx
a
ba
f (a) f (b)
I (b a)
2
Trapezoid Method
Derivation-One Interval
b b f (b) f (a)
I f ( x)dx f (a) ( x a) dx
a a
ba
b f (b) f (a) f (b) f (a)
I f (a) a x dx
a
ba ba
b 2 b
f (b) f (a) f (b) f (a) x
f (a) a x
ba a ba 2 a
f(x)
f (b)
f (a)
ba
Area f (a) f (b)
2
a b
Error of the Trapezoidal Rule
When we employ the integral under a straight line
segment to approximate the integral under a curve,
error may be:
1
Et f ( )(b a) 3
12
f (i) nf
(b a)3
Ea 2
f
12n
Example
Given a tabulated values Time (s) 0.0 1.0 2.0 3.0
of the velocity of an
object. Velocity (m/s) 0.0 10 12 14
3
Distance 0
V (t ) dt
Example 1
The interval is divided Time (s) 0.0 1.0 2.0 3.0
into 3subintervals
Velocity 0.0 10 12 14
Base points are 0,1,2,3 (m/s)
Trapezoid Method
h xi 1 xi 1
n 1
T h f ( xi ) f ( x0 ) f ( xn )
1
i 1 2
1
Distance 1(10 12) (0 14) 29
2
Algoritmos computacionales para la
regla del trapecio
Matlab Codigo: Multiples segmentos
function I = trap(func,a,b,n,varargin)
if nargin<3
error('at least 3 input arguments required');
end
if ~(b>a)
error('upper bound must be greater than lower');
end
if nargin<4||isempty(n)
n = 100;
end
x = a; h = (b-a)/n;
s=func(a,varargin{:});
for i=1:n-1
x = x + h;
s = s + 2*func(x,varargin{:});
end
s = s + func(b,varargin{:});
I = (b-a)*s/(2*n);
end
Ejemplo
Determine the distance fallen by the free-falling bungee jumper in the first 3 s by
evaluating the integral of Eq. (1). For this example, assume the following parameter
values: g = 9.81 m/s2, m = 68.1 kg, and cd = 0.25 kg/m. Note that the exact value of the
integral can be computed as 41.94805.
>> v=@(t)
…..(1) sqrt(9.81*68.1/0.25)*tanh(sqrt(9.81*0.2
5/68.1)*t)
>> format long
>> trap(v,0,3,5)
Con cd=12.5
Simpson’s Rules
a x0 b x2
( x x1 )( x x2 ) ( x x0 )( x x2 ) ( x x0 )( x x1 )
x2
I f ( x0 ) f ( x1 ) f ( x2 )dx
x0
( x0 x1 )( x0 x2 ) ( x1 x0 )( x1 x2 ) ( x2 x0 )( x2 x1 )
ba
I
h
f ( x0 ) 4 f ( x1 ) f ( x2 ) h
3 2
(b a)5 ( 4)
Et f ( ) a b
2880
• Simpson’s 1/3 rule is more accurate than trapezoidal rule.
The Multiple-Application
Simpson’s 1/3 Rule
• Just as the trapezoidal rule, Simpson’s rule can be
improved by dividing the integration interval into a
number of segments of equal width.
f ( xo ) 4 f ( x1 ) f ( x2 ) f ( x2 ) 4 f ( x3 ) f ( x4 )
I 2h 2h
6 6
f ( x n 2 ) 4 f ( x n 1 ) f ( x n ) ba
.......... 2h with h
6 n
n 1 n2
f ( xo ) f ( xn ) 4 f ( xi ) 2 f ( x j )
(b a )
i 1, 3, 5 j 2 , 4 ,6
3n
(b a)5 ( 4)
Et 4
f ( )
180n
The Multiple-Application
Simpson’s 1/3 Rule
Simpson’s 3/8 Rule
If there are 2 extra points between the integration limits
a and b, then a 3rd degree polynomial can be used
instead of the parabola to replace the function to be
integrated:
b b
I f ( x)dx f 3 ( x)dx
a a
(b a)
I f ( x0 ) 3 f ( x1 ) 3 f ( x2 ) f ( x3 ), h
3h
8 3
(b a)5 ( 4)
Et f ( ) Simpson’s 3/8 Rule
6480
Newton Cotes Integration-Example
Find the integral of:
f(x) = 0.2 +25 x – 200 x 2 + 675 x 3 – 900 x 4 + 400 x 5
Between the limits 0 to 0.8, f(0) = 0.2, f(0.8) = 0.232,
Iexact=1.640533
1. The trapezoidal rule (ans. 0.1728)
f (a) f (b) 0.2 0.232
I (b a) I (0.8 0) 0.1728
2 2
Et 1.640533 0.1728 1.467733 t 89.5%
f '' ( x) 400 4050 x 10,800 x 2 8000 x 3
0.8
f ''
( x)
0
(400 4050 x 10,800 x 2 8000 x 3 )dx
60
0.8 0
1
Ea (60)(0.8)3 2.56
12
Newton Cotes Integration-Example
2. Multiple trapezoidal rule (n=4) (ans. 1.4848)
(b a) (0.8 0)
h 0.2
4 4
h n 1
I f ( x0 ) 2 f ( xi ) f ( xn )
2 i 1
0.8
0.2 2(1.288 2.456 3.464) 0.232 1.4848
2
Newton Cotes Integration-Example
3. The Simpson 1/3 rule (ans. 1.367467)
f(0) = 0.2, f(0.4) = 0.2.456, f(0.8) = 0.232
b a 0.8 0
h 0.4
2 2
I f ( x0 ) 4 f ( x1 ) f ( x2 )
h
3
0.4
0.2 4 2.456 0.232 1.367467
3
Et 1.640533 1.367467 0.2730667 t 16.6%
f ( 4) ( x) 2400
(b a)5 ( 4) 0.85
Ea f ( ) (2400) 0.1213630
6480 6480
Pseudocódigo para las reglas de Simpson. a) Regla de Simpson 1/3
para una sola aplicación, b) regla de Simpson 3/8 para una
sola aplicación, c) regla de Simpson 1/3 de aplicación múltiple y d)
regla de Simpson de aplicación múltiple para un número de
segmentos tanto impares como pares. Observe que para todos los
casos n debe ser >= 1.