Click here to load reader
Dec 11, 2015
JAN - 2014
UNIVERSIDAD NACIONAL DE JAN
UNIVERSIDAD NACIONAL DE JAN FACULTAD DE INGENIERIA CIVIL
1
TRABAJO MTODOS NUMRICOS
a) Mtodo 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) Mtodo 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;
UNIVERSIDAD NACIONAL DE JAN 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
UNIVERSIDAD NACIONAL DE JAN 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
UNIVERSIDAD NACIONAL DE JAN 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
UNIVERSIDAD NACIONAL DE JAN 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
UNIVERSIDAD NACIONAL DE JAN 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) = ()()
Solucin:
Compilando el cdigo 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 funcin: Y= 5*x+4 - Por el mtodo analtico obtenemos que: s = 6.50 - Por el mtodo 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
UNIVERSIDAD NACIONAL DE JAN FACULTAD DE INGENIERIA CIVIL
7
Ejemplo 2: Sea la funcin: Y = 3*x - 2 - Por el mtodo analtico obtenemos que:
s = 0.50 - Por el mtodo 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 conclusin 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) = ()()
Solucin:
Ejemplo 1: Sea la funcin: Y= 3*x2 - Por el mtodo analtico obtenemos que:
s = 1.00 - Por el mtodo 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
UNIVERSIDAD NACIONAL DE JAN FACULTAD DE INGENIERIA CIVIL
8
Ejemplo 2: Sea la funcin: Y= 5*x2 - Por el mtodo analtico obtenemos que: s = 1.67 - Por el mtodo 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 conclusin para toda funcin f(x) = c2x2, por el mtodo analtico y
trapezoide compuesto el error es el mismo que al desarrollar por la formula.
5.
a) Verificar que