Sei sulla pagina 1di 9

METODOS NUMERICOS UNJ

COMANDOS

function s=traprl(f,a,b,M)
%input - f is the integrand input as string 'f'
% - a and b are upper and lower limits of integration
% -M is the number of subintervals
%Output - s is the trapezoidal 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;

function s=simprl(f,a,b,M)
%Input - f is the integrand input as a string 'f'
% - a and b are upper and lower limits of integration
% - M is the number of subintrevals
%Output - s is the simsonp 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

pg. 1
METODOS NUMERICOS UNJ

RESOLUCION DE EJERCICIOS PROPUESTOS: REGLA TRAPEZOIDAL


Y SIMPSON

a) a) function y =F(x);
y=1./(1+x.^ 2);
return;

trapr1(@F1, -1, 1, 10)


ans = 1.5675

simpr1(@F1, -1, 1, 5)
s = 1.5208
ans = 1.5208

a) function y =F(x);
y=2+sin(2.*sqrt(x));
return;

trapr1(@F1, 0, 1, 10)
ans = 2.8574

simpr1(@F1, 0, 1, 5)
s = 2.8959
ans = 2.8959

a) function y =F(x);
y=25./sqrt(x);
return;

trapr1(@F1, 0, 4, 10)
ans = Inf

simpr1(@F1, 0, 4, 5)
s = Inf
ans = Inf

a) function y =F(x);
pg. 2
METODOS NUMERICOS UNJ

y=x.*exp(-x);
return;

trapr1(@F1, 0, 4, 10)
ans = 0.89446

simpr1(@F1, 0, 4, 5)
s = 0.89824
ans = 0.89824

a) function y =F(x);
y=2.*x.*cos(x);
return;

trapr1(@F1, 0, 2, 10)
ans = 0.78330

simpr1(@F1, 0, 2, 5)
s = 0.91598
ans = 0.91598

a) function y =F(x);
y=sin(2.*x).*exp(-x);
return;

trapr1(@F1, 0, pi, 10)


ans = 0.36695

simpr1(@F1, 0, pi, 5)
s = 0.38279
ans = 0.38279

a) a) function y =F(x);
y=sqrt(1+9.*x.^4);
return;

trapr1(@F1, 0, 1, 10)

pg. 3
METODOS NUMERICOS UNJ

ans = 1.5526

simpr1(@F1, 0, 1, 5)
s = 1.5145
ans = 1.5145

a) function y =F(x);
y=sqrt(1+(cos(x)).^2);
return;

trapr1(@F1, 0, pi./4, 10)


ans = 1.0579

simpr1(@F1, 0, pi./4, 5)
s = 1.0344
ans = 1.0344

a) function y =F(x);
y=sqrt(1+exp(-2.*x));
return;

trapr1(@F1, 0, 1, 10)
ans = 1.1932

simpr1(@F1, 0, 1, 5)
s = 1.1603
ans = 1.1603

pg. 4
METODOS NUMERICOS UNJ

a) function y=F1(x)
y=2.*pi.*x.^3.*sqrt(1+9.*x.^4);
return;

trapr1(@F1, 0, 1, 10)
ans = 3.6424

simpr1(@F1, 0, 1, 5)
s = 2.9014
ans = 2.9014

a) function y=F1(x)
y=2.*pi.*sin(x).*sqrt(1+(cos(x))^2);
return;

trapr1(@F1, 0, pi/4, 10)


ans = 2.4197

simpr1(@F1, 0, pi/4, 5)
s = 2.2800
ans = 2.2800

a) function y=F1(x)
y=2.*pi.*exp(-x).*sqrt(1+exp(-2.*x));
return;

trapr1(@F1, 0, 1, 10)
ans = 4.8580

simpr1(@F1, 0, 1, 5)
s = 5.2004
ans = 5.2004

pg. 5
METODOS NUMERICOS UNJ

pg. 6
METODOS NUMERICOS UNJ

a) function y=F1(x)

pg. 7
METODOS NUMERICOS UNJ

y=cos(x);
return;

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


ans = 1.00000

a) function y=F1(x)
y=1./(5-x);
return;

trapr1(@F1, 2, 3, 5774)
ans = 0.40547

a) function y=F1(x)
y=x.*exp(-x);
return;

trapr1(@F1, 0, 2, 5774)
ans = 0.59399

a) function y=F1(x)
y=cos(x);
return;

pg. 8
METODOS NUMERICOS UNJ

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


s = 0.99995
ans = 0.99995

a) function y=F1(x)
y=1./(5-x);
return;

simpr1(@F1, 2, 3, 3652)
s = 0.40543
ans = 0.40543

a) function y=F1(x)
y=x.*exp(-x);
return;

simpr1(@F1, 0, 2, 3652)
s = 0.59397
ans = 0.59397

pg. 9

Potrebbero piacerti anche