Top Banner
JAÉN - 2014 UNIVERSIDAD NACIONAL DE JAÉN
14

Composite Simpson & Trapezoidal

Dec 11, 2015

Download

Documents

Métodos Numéricos
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Composite Simpson & Trapezoidal

JAÉN - 2014

UNIVERSIDAD NACIONAL DE JAÉN

Page 2: Composite Simpson & Trapezoidal

UNIVERSIDAD NACIONAL DE JAÉN FACULTAD DE INGENIERIA CIVIL

1

TRABAJO MÉTODOS NUMÉRICOS

a) Método simpson:

function s=simprl(f, a, b, M)

% input - f is the integrand input as string 'f'

% - a an b are upper and lower limites of integration

% - M is the number of subintervals

%Output - s is the trapezoidal rule sum

h=(b-a)/(2*M);

s1=0;

s2=0;

for k=1:M

x=a+h*(2*k-1);

s1=s1+feval(f,x);

end

for k=1:(M-1)

x=a+h*(2.*k);

s2=s2+feval(f,x);

end

s=h*(feval(f,a)+feval(f,b)+4*s1+2*s2)/3;

b) Método trapezoidal:

function s = traprl(f, a, b, M)

% input - f is integrand input as a string 'f'

% - a and b are upper and lover limits of integration

% - M is tha number of subintervals

% cutput - s is tha trapezoildal rule sum

h = (b - a)/M;

s = 0;

for k=1:(M-1);

x= a+h*k;

s= s+feval(f, x);

end

s=h*(feval(f,a)+feval(f,b))/2+h.*s;

Page 3: Composite Simpson & Trapezoidal

UNIVERSIDAD NACIONAL DE JAÉN FACULTAD DE INGENIERIA CIVIL

2

1. Approximate each integral using:

USING INDICATION

COMPOSITE TRAPEZOIDAL

M=10

COMPOSITE SIMPSON

M=5

Function

F1(x)=∫ (𝟏 + 𝒙𝟐)𝒅𝒙𝟏

−𝟏

Editor

function Y= F1(X);

Y=(1+X.^2).^-1;

return;

function Y= F1(X);

Y=(1+X.^2).^-1;

return;

Terminal

>>> traprl(@F1, -1, 1, 10) >>> simprl(@F1, -1, 1, 5)

ans = 1.5675 s = 1.5708

ans = 1.5708

Function

F2(x)=∫ (𝟐 + 𝐬𝐢𝐧 (𝟐√𝒙))𝒅𝒙𝟏

𝟎

Editor

function Y= F2(X);

Y=2+sin(2*X.^(1/2));

return;

function Y= F2(X);

Y=2+sin(2*X.^(1/2));

return;

Terminal

>>>traprl(@F2, 0, 1, 10) >>> simprl(@F2, 0, 1, 5)

ans = 2.8574 s = 2.8656

ans = 2.8656

Function

F3(x)= ∫ 𝒅𝒙/√𝒙𝟒

𝟎.𝟐𝟓

Editor

function Y= F3(X);

Y=1/X.^(1/2);

return;

function Y= F3(X);

Y=1/X.^(1/2);

return;

Terminal

>>> traprl(@F3, 0.25, 4, 10) >>> simprl(@F3, 0.25, 4, 5)

ans = 3.0419 s = 3.0076

ans = 3.0076

Page 4: Composite Simpson & Trapezoidal

UNIVERSIDAD NACIONAL DE JAÉN FACULTAD DE INGENIERIA CIVIL

3

Function

F4(x)=∫ 𝒙𝟐𝒆−𝒙𝒅𝒙𝟒

𝟎

Editor

function Y= F4(X);

Y=(X.^2)*exp(- X);

return;

function Y= F4(X);

Y=(X.^2)*exp(- X);

return;

Terminal

>>> traprl(@F4, 0, 4, 10) >>> simprl(@F4, 0, 4, 5)

ans = 1.5216 s = 1.5246

ans = 1.5246

Function

F5(x)=∫ 𝟐𝒙𝒄𝒐𝒔(𝒙)𝒅𝒙𝟐

𝟎

Editor

function Y= F5(X);

Y=2*X*cos(X);

return;

function Y= F5(X);

Y=2*X*cos(X);

return;

Terminal

>>> traprl(@F5, 0, 2, 10) >>> simprl(@F5, 0, 2, 5)

ans = 0.78330 s = 0.80500

ans = 0.80500

Function

F6(x)=∫ 𝐬𝐢𝐧 (𝟐𝒙)𝒆−𝒙𝒅𝒙𝝅

𝟎

Editor

function Y= F6(X);

Y=sin(2*X)*exp(- X);

return;

function Y= F6(X);

Y=sin(2*X)*exp(- X);

return;

Terminal

>>> traprl(@F6, 0, pi, 10) >>> simprl(@F6, 0, pi, 5)

ans = 0.36695 s = 0.38279

ans = 0.38279

Page 5: Composite Simpson & Trapezoidal

UNIVERSIDAD NACIONAL DE JAÉN FACULTAD DE INGENIERIA CIVIL

4

2. DETERMINAR LA LONGITUD DE LA CURVA: L= √𝟏 + (𝒇′(𝒙)𝟐)𝒅𝒙

USING

INDICATION

COMPOSITE TRAPEZOIDAL

M=10

COMPOSITE SIMPSON

M=5

Function

F7(x)= x3 𝟎 ≤ 𝑿 ≤ 𝟏

Editor

function A= F7(X); A=(1+((1/3).*X.^2).^2).^(1/2);

return;

function A= F7(X); A=(1+((1/3).*X.^2).^2).^(1/2);

return;

Terminal

>>> traprl(@F7, 0, 1, 10) >>> simprl(@F7, 0, 1, 5)

ans = 1.0111 s = 1.0109

ans = 1.0109

Function

F8(x)=sin(x) 𝟎 ≤ 𝑿 ≤ 𝝅/𝟒

Editor

function A= F8(X); A=(1+(cos(X)).^2).^(1/2);

return;

function A= F8(X); A=(1+(cos(X)).^2).^(1/2);

return;

Terminal

>>> traprl(@F8, 0, pi./4, 10) >>> simprl(@F8, 0, pi./4, 5)

ans = 1.0579 s = 1.0581

ans = 1.0581

Function

F9(x)=e-5 𝟎 ≤ 𝑿 ≤ 𝟏

Editor

function A= F9(X); A=(1+(- exp(-X)).^2).^(1/2);

return;

function A= F9(X); A=(1+(- exp(-X)).^2).^(1/2);

return;

Terminal

>>> traprl(@F9, 0, 1, 10) >>> simprl(@F9, 0, 1, 5)

ans = 1.1932

s = 1.1927

ans = 1.1927

Page 6: Composite Simpson & Trapezoidal

UNIVERSIDAD NACIONAL DE JAÉN FACULTAD DE INGENIERIA CIVIL

5

3. DETERMINAR AREA: A= ∫ 𝒇(𝒙)√𝟏 + (𝒇′(𝒙))𝟐 𝒅𝒙𝒃

𝒂

using

COMPOSITE TRAPEZOIDAL

M=10

COMPOSITE SIMPSON

M=5

Function

F10(x)= x3 𝟎 ≤ 𝑿 ≤ 𝟏

Editor

function L= F(X);

L= X.^3.* (1+(0.5.*X.^3)).^(1/2);

return;

function L= F10(X);

L= X.^3.*(1+(0.5.*X.^3)).^(1/2);

return;

Terminal

>>> traprl(@F10, 0, 1, 10) >>> simprl(@F10, 0, 1, 5)

ans = 0.25963 s = 0.25683

ans = 0.25683

Function

F11(x)=sin(x) 𝟎 ≤ 𝑿 ≤ 𝝅/𝟒

Editor

function L= F11(X);

L= sin(X).*(1+(0.5.*cos(X).^3)).^(1/2);

return;

function L= F11(X);

L= sin(X).*(1+(0.5.*cos(X).^3)).^(1/2);

return;

Terminal

>>> traprl(@F11, 0, pi./4, 10) >>> simprl(@F11, 0, pi./4, 5)

ans = 0.38511 s = 0.38554

ans = 0.38554

Function

F12(x)=e-5 𝟎 ≤ 𝑿 ≤ 𝟏

Editor

function L= F12(X);

L= exp(-X).*(1+(0.5.*exp(-X).^3)).^(1/2);

return;

function L= F12(X);

L= exp(-X).*( (1+(0.5.*exp(-X).^3)).^(1/2);

return;

Terminal

>>> traprl(@F12, 0, 1, 10) >>> simprl(@F12, 0, 1, 5)

ans = 0.77318 s = 0.77178

ans = 0.77178

Page 7: Composite Simpson & Trapezoidal

UNIVERSIDAD NACIONAL DE JAÉN FACULTAD DE INGENIERIA CIVIL

6

4.

a) Verificar que la regla trapezoidal (M=1, h=1) es exacta para polinomios de grado < 1 de la forma f(x) = c1x + c0 con [0, 1] es:

Et (f, h) = −(𝒃−𝒂)𝒇𝟐(𝒄)𝒉𝟐

𝟏𝟐

Solución:

Compilando el código con las condiciones del problema:

function s = traprl(f, a, b, M)

% input - f is integrand input as a string 'f'

% - a and b are upper and lover limits of integration

% - M is tha number of subintervals

% cutput - s is tha trapezoildal rule sum

h = (b - a)/M;

s = 0;

for k=1:(M-1);

x= a+h*k;

s= s+feval(f, x);

end

s=h*(feval(f,a)+feval(f,b))/2+h.*s;

Ejemplo 1: Sea la función: Y= 5*x+4 - Por el método analítico obtenemos que: s = 6.50 - Por el método del trapecio compuesto y con las condiciones que nos

piden obtenemos:

function Y=F1(x); Y= 5.*x+4; return;

s = traprl(@F1,0,1,1) s = 6.5000

Page 8: Composite Simpson & Trapezoidal

UNIVERSIDAD NACIONAL DE JAÉN FACULTAD DE INGENIERIA CIVIL

7

Ejemplo 2: Sea la función: Y = 3*x - 2 - Por el método analítico obtenemos que:

s = 0.50 - Por el método del trapecio compuesto y con las condiciones que nos

piden obtenemos:

function Y=F1(x); Y= 3.*x - 2; return; s = traprl(@F1,0,1,1) s = -0.50000

Como las áreas son positivas le damos valor absoluto con la cual el resultado es 0.50

Si el Et (f, h) = −(𝒃−𝒂)𝒇𝟐(𝒄)𝒉𝟐

𝟏𝟐 = 0

En conclusión para todos los ejemplos el error es 0 es decir es exacta.

b) Usar la integral f(x) = c2x2 y verificar que el plazo de error para la regla trapezoidal (M = 1, h = 1) en el intervalo [0, 1] es:

Er (f, h) = −(𝐛−𝐚)𝐟𝟐(𝐜)𝐡𝟐

𝟏𝟐

Solución:

Ejemplo 1: Sea la función: Y= 3*x2 - Por el método analítico obtenemos que:

s = 1.00 - Por el método del trapecio compuesto y con las condiciones que nos

piden obtenemos: function Y= F1(x); Y= 3.*x.^2; return; s=traprl(@F1,0,1,1) s = 1.5000

Et (f, h) = −(𝐛−𝐚)𝐟𝟐(𝐜)𝐡𝟐

𝟏𝟐 =

−(𝟏−𝟎)𝟔∗𝟏𝟐

𝟏𝟐 = -0.50

Page 9: Composite Simpson & Trapezoidal

UNIVERSIDAD NACIONAL DE JAÉN FACULTAD DE INGENIERIA CIVIL

8

Ejemplo 2: Sea la función: Y= 5*x2 - Por el método analítico obtenemos que: s = 1.67 - Por el método del trapecio compuesto y con las condiciones que nos

piden obtenemos: function Y= F1(x); Y= 5*x. ^2; return; s=traprl(@F1,0,1,1) s = 2.5000

Et (f, h) = −(𝐛−𝐚)𝐟𝟐(𝐜)𝐡𝟐

𝟏𝟐 =

−(𝟏−𝟎)𝟏𝟎∗𝟏𝟐

𝟏𝟐 = -0.83

- En conclusión para toda función f(x) = c2x2, por el método analítico y

trapezoide compuesto el error es el mismo que al desarrollar por la formula.

5.

a) Verificar que la regla Simpson (M=1, h=1) es exacta para polinomios de grado < 3 de la forma f(x) = c3x3 + c2x2+ c1x + c0 con [0, 2] es:

Es (f, h) = −(𝒃−𝒂)𝒇𝟒(𝒄)𝒉𝟒

𝟏𝟖𝟎

Solución:

Compilando el código con las condiciones del problema

function s = traprl(f, a, b, M)

% input - f is integrand input as a string 'f'

% - a and b are upper and lover limits of integration

% - M is tha number of subintervals

% cutput - s is tha trapezoildal rule sum

h = (b - a)/M;

s = 0;

for k=1:(M-1);

x= a+h*k;

s= s+feval(f, x);

end

s=h*(feval(f,a)+feval(f,b))/2+h.*s;

Page 10: Composite Simpson & Trapezoidal

UNIVERSIDAD NACIONAL DE JAÉN FACULTAD DE INGENIERIA CIVIL

9

Ejemplo 1: Sea la función: Y= 3*x3+4*x2+x -2

- Por el método analítico obtenemos que: s = 20.67 - Por el método de Simpson y con las condiciones que nos piden

obtenemos: function Y = F1(x); Y=3.*x.^3+4.*x.^2+x-2; return;

simprl(@F1,0,2,1) s = 20.667

- Por lo tanto el error es:

Es (f, h) = −(𝒃−𝒂)𝒇𝟒(𝒄)𝒉𝟒

𝟏𝟖𝟎 =

−(𝟐−𝟎)𝟎𝟒∗𝟏𝟒

𝟏𝟖𝟎 = 0

- En conclusión para todos los ejemplos el error es 0 es decir es exacta.

b) Usar la integral f(x) = c4x4 y verificar que el plazo de error para la regla

Simpson (M = 1, h = 1) en el intervalo [0, 2] es:

Es (f, h) = −(𝐛−𝐚)𝐟𝟒(𝐜)𝐡𝟒

𝟏𝟖𝟎

Sea la función: Y= 6*x4 - Por el método analítico obtenemos que: s = 38.40 - Por el método del trapecio compuesto y con las condiciones que nos

piden obtenemos:

function Y=F1(x); Y =6.*x. ^4; return;

s = simprl(@F1,0,2,1) s = 40

Es (f, h) = −(𝐛−𝐚)𝐟𝟒(𝐜)𝐡𝟒

𝟏𝟖𝟎 =

−(𝟐−𝟎)𝟏𝟒𝟒∗𝟏𝟒

𝟏𝟖𝟎 = -1.60

- En conclusión para toda función f(x) = c4x4, por el método analítico y Simpson el error es el mismo que al desarrollar por la formula.

Page 11: Composite Simpson & Trapezoidal

UNIVERSIDAD NACIONAL DE JAÉN FACULTAD DE INGENIERIA CIVIL

10

6. The number Mand the interval width h so that the composite

trapezoidal rule for M subintervals can be used to compute the given

intregal wich an accuracy of 5 x10-9

a) ∫ 𝒄𝒐𝒔(𝒙)𝒅𝒙𝝅/𝟔

−𝝅/𝟔 b) ∫

𝟏

𝟓−𝒙𝒅𝒙

𝟑

𝟐 c) ∫ 𝒙𝒆−𝟏𝒅𝒙

𝟐

𝟎

Hint for part (c). ∫ (𝒙) = 𝟖𝒙 − 𝟐)𝒆−𝒙(𝟐)

Solucion:

𝐸𝑇 = 5 ∗ 10−9

𝐸𝑇 = −1

2 𝑓′′(𝑐)(𝑏 − 𝑎)ℎ2……………………ℎ2 =

(𝑏−𝑎)2

𝑀2

𝐸𝑇 = −1

12 𝑓2(𝑐)(𝑏 − 𝑎)ℎ2

𝐸𝑇 = −1

12

𝑓2(𝑐)(𝑏 − 𝑎)3

𝑀2

como ∶ f 2(x) = (x − 2)e−x

reemplazamos en ∶

5 ∗ 10−9 = −1

12

(𝑥 − 2). 𝑒−𝑥(1)3

𝑀2

5 ∗ 10−9 = −1

12.−2

𝑀2

𝑀 = √2

12(5 ∗ 10−9)= √

1

30 ∗ 10−9

𝑴 = 𝟓𝟕𝟕𝟒

Page 12: Composite Simpson & Trapezoidal

UNIVERSIDAD NACIONAL DE JAÉN FACULTAD DE INGENIERIA CIVIL

11

a) function y=F1(x)

y=cos(x);

return;

trapr1(@F1, -pi/6, pi/6, 5774)

ans = 1.00000

b) function y=F1(x)

y=1./(5-x);

return;

trapr1(@F1, 2, 3, 5774)

ans = 0.40547

c) function y=F1(x)

y=x.*exp(-x);

return;

trapr1(@F1, 0, 2, 5774)

ans = 0.59399

Page 13: Composite Simpson & Trapezoidal

UNIVERSIDAD NACIONAL DE JAÉN FACULTAD DE INGENIERIA CIVIL

12

7. determine the number M and the interval width h so that the

composite Simpson rule for 2M subnivelals can be used to compute

the given integral with an accuracy of 5 x 10-9

a) ∫ 𝒄𝒐𝒔(𝒙)𝒅𝒙𝝅/𝟔

−𝝅/𝟔 b) ∫

𝟏

𝟓−𝒙𝒅𝒙

𝟑

𝟐 c) ∫ 𝒙𝒆−𝟏𝒅𝒙

𝟐

𝟎

Hint for part (c). ∫ (𝒙) = ( 𝒙 − 𝟒)𝒆−𝒙(𝟒)

Solucion:

𝑬𝒔 = −(𝒃 − 𝒂)𝟓. 𝒇𝟒

𝟏𝟖𝟎𝑴𝟒

𝒇𝟒(𝒙) = (𝒙 − 𝟒). 𝒆−𝒙 𝒑𝒂𝒓𝒂 𝒙 = 𝟎, 𝒉 = 𝟏

𝐸𝑠 = −(𝑏 − 𝑎)5. (𝑥 − 4). 𝑒−𝑥

180𝑀4

5 ∗ 10−9 = −(−4)(𝑒0)(15)

180𝑀4

𝑀 = √4. 15

(180)(5 ∗ 10−9)

4

𝑴 = 𝟒𝟔. 𝟎𝟐

2𝑀 = 92 … … … … 𝑁° 𝑑𝑒 𝑝𝑎𝑟𝑡𝑖𝑐𝑖𝑜𝑛𝑒𝑠

a) function y=F1(x)

y=cos(x);

return;

simpr1(@F1, -pi/6, pi/6, 92)

s = 0.99995

ans = 0.99995

Page 14: Composite Simpson & Trapezoidal

UNIVERSIDAD NACIONAL DE JAÉN FACULTAD DE INGENIERIA CIVIL

13

b) function y=F1(x)

y=1./(5-x);

return;

simpr1(@F1, 2, 3, 92)

s = 0.40543

ans = 0.40543

c) function y=F1(x)

y=x.*exp(-x);

return;

simpr1(@F1, 0, 2, 92)

s = 0.59397

ans = 0.59397