Está en la página 1de 11

LABORATORIO N8

METODOS NUMERICOS
Alumno: Ojeda Dominguez Deyanira

Cdigo: 13190059

1. La funcin dif permite el clculo de derivadas exactas.


CODIFICACIN EN MATLAB
syms x
f=exp(x)*sin(x);
fd=diff(f)
subs(fd,1) % evaluando la derivada
en x=1
RESULTADOS

2. Dados los siguientes puntos obtener la derivada a partir de


un polinomio interpolante:
CODIFICACIN EN MATLAB
x=[0 0.1 0.2 0.4 0.5 0.55]
y=[1.12 1.28 1.55 1.88 1.77 1.66]
p=polyfit(x,y,length(x)-1)
dp=polyder(p)
xi=[0 0.25 0.50] % Evaluar
p"(0.25) p"(0.50)
dpxi=polyval(dp,xi)

RESULTADOS:

p"(0)

3. Obtener la derivada a partir de puntos calculados con una


funcin.
CODIFICACIN EN MATLAB
%pruebadiff1.m
f=inline('x.^2.*exp(x)');
df=inline('(x.^2+2*x).*exp(x)');
x=0:0.25:1;
y=f(x);
p=polyfit(x,y,length(x)-1);
dp=polyder(p)
xi=[0 0.25 0.50 0.8 1 1.1 1.2];
dpxi=polyval(dp,xi)
dfxi=df(xi)
err=abs(dpxi-dfxi)

RESULTADOS

4. Uso de frmulas de diferenciacin de dos puntos.


CODIFICACIN EN MATLAB
f=inline('x.^2.*exp(x)');
df=inline('(x.^2+2*x).*exp(x)')
;
x=1;
h=0.1;
dfa=(f(x+h)-f(x))/h
dfe=df(x)
err=abs(dfe-dfa)
RESULTADOS:

5. Clculo de Integrales indefinidas, se utiliza el comando int.


CODIFICACIN EN MATLAB
syms t; % variable simblica
f=inline('cos(x)*exp(x)');
int(f(t),t)
pretty(ans) % reescribimos
RESULTADOS:

6. Integrales definidas: La misma instruccin int, permite


realizar la integracin definida. A modo de ejemplo.
CODIFICACIN EN MATLAB
syms t; % variable simblica
int((t^2+4*t)/(t^42*t^2+1),t,2,5)
double(ans)
RESULTADOS:

7. La funcin quad permite obtener integrales en forma


numrica.
CODIFICACIN EN MATLAB
syms t; % variable simblica
f=inline('exp(x).*sin(x)')
I=quad(f,1,2)

RESULTADOS

8. Aproxime:
1

e x ( x 2+ 2 x ) dx
0

Usando la regla del trapecio ( h=1 )


CODIFICACIN EN MATLAB
syms t; % variable simblica
f1=inline('exp(x).*(x.^2+2*x)')
h=1
Ie=exp(1)
I=h/2*(f1(0)+f1(1))
err=abs(Ie-I)
% Usando la regla del trapecio con h=1/2
h=0.5
I=h/2*(f1(0)+2*f1(0.5)+f1(1))
err=abs(Ie-I)
err = 0.3509

RESULTADOS:

9. Escriba
compuesta.

una

funcin

CODIFICACIN EN MATLAB
% trapecio.m
function
I=trapecio(fname,a,b,n)
h=(b-a)/n;
x=a:h:b;
f=feval(fname,x);
I=h/2*(f(1)+2*sum(f(2:n))
RESULTADOS:

para

la

frmula

del

trapecio

10. Resuelva la integral anterior usando la regla de Simpson


1/3, h=0.5 y h=1/8 .
CODIFICACIN EN MATLAB
h=0.5
I=h/3*(f1(0)+4*f1(0.5)+f1(1)
)
% Evale la integral con
h=1/8.
h=1/8
I=h/3*(f1(0)+4*f1(0.5)+f1(1)
)
RESULTADOS:

11. Escriba una funcin para la formula compuesta de


Simpson 1/3.
CODIFICACIN EN MATLAB
% sim13.m
% Formula compuesta de Simpson 1/3
% n : Numero total de particiones debe ser par
function I=sim13(fname,a,b,n)
if rem(n,2)==0
h=(b-a)/n;
x=a:h:b;
f=feval(fname,x);
I=h/3*(f(1)+4*sum(f(2:2:n))+ 2*sum(f(3:2:n1))+f(n+1));
else
disp('Lo siento n debe ser par!!!')
end

RESULTADOS:

12. Aproxime usando la regla del rectngulo:


1

1
dx
log ( x )

CODIFICACIN EN MATLAB
f2=inline('1./sqrt(log10(x))')
h=0.5
I=2*h*f2(0.5)
h=0.25
I=2*h*f2(0.25)+2*h*f2(
0.75)
RESULTADOS:

13. Elabore la siguiente funcin:


CODIFICACIN EN MATLAB
function I=rectangulo(f2,a,b,n)
h=(b-a)/n
I=2*h*f2(0.25)+2*h*f2(0.75)
RESULTADOS

14. Aproximar mediante cuadratura de Gauss.


1

( x 2+2 x ) e x dx
1

CODIFICACIN EN MATLAB

f1=inline('exp(x).*(x.^2+2*x)')
I1=2*f1(0)
I2=f1(-0.5774)+f1(0.5774)
Ie=exp(1)-exp(-1)
err=abs(I2-Ie)

RSULTADOS:

15. Utilizando la cuadratura de Gauss-Legendre, estime la


siguiente integral.
1.5

et dx
1

CODIFICACIN EN MATLAB
f2=inline('0.25*exp(((x+5)/4)^2)')
I1=2*f2(0)
I2=f2(-0.5774)+f2(0.5774)
es=abs(I2-I1)
RESULTADOS:

También podría gustarte