Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Facultad de Ingeniera
INFORME
DE
MENU DE METODOS NUMERICOS
Presentado por:
Ao: Tercero
Semestre: I
TACNA PER
2012
INTRODUCCION
resolver analticamente.
como herramientas para crear sus propios programas respecto a estos modelos.
METODO DE LA BISECCION
y= f(x)
Raz
x3 x 4
a a a
b
x2 x1
b b
Si la funcin f(x) es real y continua en [a,b] y f(a)f(b)<0, entonces existe una raz entre a y b
PROCEDIMIENTO
PASO 1:
Escoger los valores iniciales a y b ([a;b])tal que f(a) f(b)<0
PASO 2:
PASO 3:
Realizar las siguientes evaluaciones para determinar en que sub-intervalo cae la raz.
PASO 4:
PASO 5:
El proceso se repetir mientras b - a<E, donde E es una tolerancia prefijada, por ejemplo:
o E = 1% (0.01)
o E = 0.1%
o E = 0.01%
DIAGRAMA DE FLUJO
PROGRAMACION
f=inline(get(handles.edit1,'string'));
a=str2double(get(handles.edit2,'string'));
b=str2double(get(handles.edit3,'string'));
E=str2double(get(handles.edit4,'string'));
if f(a)*f(b)<0 ;
x=(a+b)/2
if f(a)*f(x)==0
a=b;
else
if f(a)*f(x)<0;
a=x;
else
b=x;
end
end
end
set(handles.edit6,'string',x);
else
set(handles.edit6,'string','no existe raiz');
end
PARTE GRAFICA
f=inline(get(handles.edit1,'string'));
intervalos=str2num(get(handles.edit5,'string'));
ezplot(f,intervalos)
grid on
zoom on
y=x
y = g(x)
PASO 2:
Empezar el desarrollo con un valor inicial x 0 y determinar los xk+1, mediante xk+1 = g(xk)
PASO 3:
El proceso se repetir hasta que x k+1 - xk<E donde E es una tolerancia prefijada, por
INICIO
ejemplo E=1%
El punto xktal que g(xk)= xkes un punto fijo de g(x); este punto fijo es una raz de f(x)=0
VENTAJAS Y DESVENTAJAS
LEER
Las ventajas es que se puede obtener fcilmente la funcin de iteracin g(x).
f(x),g(x),x0,E
La desventaja es que los x1,x2x3, no siempre converjan a un punto con la funcin g(x)
elegida. En este caso para probar la convergencia de g(x) se debe verificar que:
x1g(x0)de la raz
g(x)<1 es una vecindad
x1-x0>E
X0X1
X1g(x)
DIAGRAMA DE FLUJO
ESCRIBIR
x1
FIN
PROGRAMACION
g=inline(get(handles.edit2,'string'));
x0=str2double(get(handles.edit3,'string'));
E=str2double(get(handles.edit4,'string'));
x1=g(x0)
while abs (x1-x0)>E
x0=x1;
x1=g(x0)
end
set(handles.edit5,'string',x1);
PARTE GRAFICA
f(x)=0 y=f(x)
function pushbutton2_Callback(hObject, eventdata, handles)
g=inline(get(handles.edit2,'string'));
intervalos=str2num(get(handles.edit6,'string'));
ezplot(handles.axes1,g) (xo;f(xo))
grid on
(x1;f(x1))
x2
xi+1
Raz
Pero mL = f(x0)
Entonces:
(x0-x1)f(x0)=f(xo)
f(xi)o
LEER
F(X),F(X),X0,E
F
|X1-X0|>E
X0X1
DIAGRAMA DE FLUJO
ESCRIBIR
X1
X1
FIN
PROGRAMACION
f=inline(get(handles.edit1,'string'));
g=inline(get(handles.edit2,'string'));
x=str2double(get(handles.edit3,'string'));
E=str2double(get(handles.edit4,'string'));
x1=x-f(x)/g(x);
while abs (x1-x)>E
x=x1;
x1=x-f(x)/g(x);
end
set(handles.edit6,'string',x1);
PARTE GRAFICA
f=inline(get(handles.edit1,'string'));
ezplot(f),grid on
METODO DE LA SECANTE
y = f(x)
C
f(x) = 0 (xo,f(xo))
r : raz
(x1,f(x1)) B
A
x3
r x2 x1 x0S
mAB= mBC
Generalizando se tiene:
secante)
INICIO
LEER
F(X),X0,X1,E
|X2-X1|>E
V
X0X1
X1X2
ESCRIBIR
X2
FIN
PROGRAMACION
f=inline(get(handles.edit1,'string'));
x0=str2double(get(handles.edit2,'string'));
x1=str2double(get(handles.edit3,'string'));
E=str2double(get(handles.edit4,'string'));
x2=x1-(((x1-x0)*f(x1))/(f(x1)-f(x0)))
while abs(x2-x1)>E
x0=x1;
x1=x2;
x2=x1-(((x1-x0)*f(x1))/(f(x1)-f(x0)));
end
set(handles.edit5,'string',x2);
PARTE GRAFICA
f=inline(get(handles.edit1,'string'));
intervalos=str2num(get(handles.edit5,'string'));
ezplot(handles.axes1,f)
grid on
METODO DE MULLER
f(x) = 0
r : raz
(x0;f(x0))
(x1;f(x1))
y = f (x)
Inicial
(x2;f(x2))
r X3 X2 X1 X0
Parbola
Raz aproximada
f(x) = ax2+bx+c
y =?
y = x2 y = (x-4)2
x2y=(x-x2)2
y = a(x-x2)2+b(x-x2)+c
y = ax2 + bx + c (Ecuacin
general de la parbola)
x2
El mtodo consiste en obtener los coeficientes de la parbola que pasa por los tres puntos,
dichos coeficientes se sustituyen en la formula cuadrtica para obtener el valor donde la
parbola intersecta al eje x, es decir x3.
La aproximacin se facilita al escribir la ecuacin de la parbola de la siguiente forma:
f(x) = a(x-x2)2+b(x-x2)+c
Como la parbola pasa por los puntos (xo,f(xo);(x1,f(x1)) y (x2,f(x2)) entonces se tiene:
o f(x0) = a(x0-x2)2+b(x0-x2)+c
o f(x1) = a(x1-x2)2+b(x1-x2)+c
o f(x2) = a(x2-x2)2+b(x2-x2)+c
o f(x2) = c
Objetivo: Hallar a y b
Utilizando las siguientes nuevas variables:
ho = x1 - x0
h1 = x2 - x1
0 =
1 =
o
o ah1 + 1
o f(x2)
f=inline(get(handles.edit1,'string'));
x0=str2double(get(handles.edit2,'string'));
x1=str2double(get(handles.edit3,'string'));
x2=str2double(get(handles.edit4,'string'));
E=str2double(get(handles.edit5,'string'));
h0=x1-x0;
h1=x2-x1;
d0=(f(x1)-f(x0))/(x1-x0);
d1=(f(x2)-f(x1))/(x2-x1);
a=(d1-d0)/(h1+h0);
b=a*h1+d1;
c=f(x2);
if b>0
x3=x2-2*c/(b+sqrt(b^2-4*a*c))
else
x3=x2-2*c/(b-sqrt(b^2-4*a*c))
end
while abs((x3-x2)/x3)>E
x0=x1
x1=x2
x2=x3
h0=x1-x0;
h1=x2-x1;
d0=(f(x1)-f(x0))/(x1-x0);
d1=(f(x2)-f(x1))/(x2-x1);
a=(d1-d0)/(h1+h0);
b=a*h1+d1;
c=f(x2);
if b>0
x3=x2-2*c/(b+sqrt(b^2-4*a*c))
else
x3=x2-2*c/(b-sqrt(b^2-4*a*c))
end
end
set(handles.edit6,'string',x3)
PARTE GRAFICA
f=inline(get(handles.edit1,'string'));
intervalo=str2num(get(handles.edit7,'string'));
ezplot(f,intervalo);
grid on
CAPITULO II
AJUSTES DE CURVAS
Dado un conjunto de puntos, el estudiante analizara que es lo mas conveniente utilizar, si ajustar
El ajuste de curvas es un proceso mediante el cual, dado un conjunto de N pares de puntos {xi,
f(x) de tal manera que la suma de los cuadrados de la diferencia entre la imagen real y la
REGRESION LINEAL
Cuando se tienen parejas de valores (x, y), tabulados como los dados en tabla, y se
quiere estimar el valor de la funcin f(x) solamente para un valor de la variable
independiente x, el problema se resuelve con la interpolacin o extrapolacin, segn
que el valor por estimar se encuentre entre o fuera de los datos discretos conocidos,
respectivamente. Sin embargo, en muchos de los casos se desea tener una ecuacin
que represente todos esos datos y que con slo proponer ( en ella ) valores de x se
obtengan los valores de la funcin de manera inmediata. dada por:
Si hacemos esta prctica para cada punto y, tomando en cuenta que, el cuadrado de
esta diferencia ser an ms pequea, entonces el error total simbolizado por E, para
todos los puntos puede escribirse,
x=str2num(get(handles.edit1,'string'));
y=str2num(get(handles.edit2,'string'));
n=length(x);
A11=0;A12=0;A22=n;B1=0;B2=0;
for i=1:n
A11=A11+x(i)^2;
A12=A12+x(i);
A21=A12;
B1=B1+x(i)*y(i);
B2=B2+y(i);
End
a=(B1*A22-B2*A12)/(A11*A22-A21*A12);
b=(B2*A11-B1*A21)/(A11*A22-A21*A12);
cadena=sprintf('y=%8.6f+%8.6fx',b,a);
set(handles.edit3,'string',cadena);
PARTE GRAFICA
x=str2num(get(handles.edit1,'string'));
y=str2num(get(handles.edit2,'string'));
n=length(x);
A11=0;A12=0;A22=n;B1=0;B2=0;
for i=1:n
A11=A11+x(i)^2;
A12=A12+x(i);
A21=A12;
B1=B1+x(i)*y(i);
B2=B2+y(i);
End
a=(B1*A22-B2*A12)/(A11*A22-A21*A12);
b=(B2*A11-B1*A21)/(A11*A22-A21*A12);
xx=(min(x)-1):0.2:(max(x)+1);
yy=a.*xx+b;
plot(x,y,'*',xx,yy)
grid on
REGRESION POLINOMIAL
Considerando que g(x) corresponde a un polinomio de grado l, la ecuacin se
transforma en,
LEER
m,x,y
A11=0
A12=0
A22=m
B1=0
B2=0
i=1;m;1
A11=A11+((x(i))^2)
A12=A12+x(i)
A21=A12
B1=B1+(x(i)*y(i))
B2=B2+y(i)
a=((B1*A22)-(B2*A12))/((A11*A22)-(A12*A21));
b=((B2*A11)-(B1*A21))/((A11*A22)-(A12*A21));
escribir
a,b
PROGRAMACION
x=str2num(get(handles.edit1,'string'));
y=str2num(get(handles.edit2,'string'));
m=length(x);
n=str2num(get(handles.edit3,'string'));
for j=1:n+1
for k=1:n+1
s1=0;
for i=1:m
s1=s1+(x(i)^(j+k-2));
end
A(j,k)=s1;
end
end
for j=1:n+1
s2=0;
for i=1:m
s2=s2+(y(i)*(x(i)^(j-1)));
end
B(j)=s2;
end
B=B';
a=inv(A)*B;
a=a';
set(handles.edit4,'string',num2str(a));
PARTE GRAFICA
x=str2num(get(handles.edit1,'string'));
y=str2num(get(handles.edit2,'string'));
m=length(x);
n=str2num(get(handles.edit3,'string'));
for j=1:n+1
for k=1:n+1
s1=0;
for i=1:m
s1=s1+(x(i)^(j+k-2));
end
A(j,k)=s1;
end
end
for j=1:n+1
s2=0;
for i=1:m
s2=s2+(y(i)*(x(i)^(j-1)));
end
B(j)=s2;
end
B=B';
a=inv(A)*B;
a=a';
a=fliplr(a);
b=min(x):0.1:max(x);
p=polyval(a,b);
plot(x,y,'or',b,p),grid on
xlabel('Coordenadas X');
ylabel('Coordenadas Y');
title('REGRESION POLINOMIAL');
INTERPOLACIN DE LAGRANGE
for k=1:n
Num=1;
Den=1;
for i=1:n
if k ~=i;
Num=Num*(xx-x(i));
Den=Den*(x(k)-x(i));
end
La=Num/Den;
end
s=s+La*f(x(k));
end
set(handles.edit4,'string',s);
CAPITULO III
LINEALES
5.1 -TEORIA:
Como hemos visto, el mtodo de Gauss transforma la matriz de coeficientes en una matriz
triangular superior. El mtodo de Gauss-Jordan contina el proceso de transformacin hasta
El sistema de ecuaciones anterior es, como hemos visto, fcil de resolver. Obtenemos las
soluciones:
DIAGRAMA DE FLUJO
INICIO
LEER
n , aij
i=0,n,1
divisor = aii
j = i , n + 1, 1
k=1,n,1
i~=k
pivote=a(k,i)
j = i, n, 1
ESCRIBIR
ai,n+1
FIN
PROGRAMACION
A=str2num(get(handles.edit1,'string'));
[m,n]=size(A);
for i=1:m
divisor=A(i,i);
for j=i:n
A(i,j)=A(i,j)/divisor;
end
for k=1:m
if i~=k
pivote = A(k,i);
for j=i:n
A(k,j)=A(k,j)- pivote*A(i,j);
end
end
end
end
for i=1:m
x(i)=A(i,n);
end
x=x';
t=1:m;
t=t';
cadena='';
for t=1:m
cad=sprintf('x%d=%6.2f',t,x(t));
cadena=[cadena;cad];
end
Si tenemos en cuenta la peculiar forma de las matrices Q y R, resulta que todos los sumandos
para los que j > i en la parte izquierda son nulos, mientras que en la parte derecha son nulos
DIAGRAMA DE FLUJO
INICIO
LEER
N, m , aij, bi, vi
K = 1, m, 1
i = 1, n, 1
Xi = Vi
i = 1, n, 1
s=0
j=1, n, 1
j ~= 1
s = s + aij*xj
vi = (bi-s)/aii
Xi = vi
i = 1, n, 1
ESCRIBIR
vi
FIN
PROGRAMACION
maxite=str2double(get(handles.edit1,'string'));
v=str2num(get(handles.edit3,'string'));
a=str2num(get(handles.edit2,'string'));
b=str2num(get(handles.edit4,'string'));
[n,n]=size(a);
cad1='';
for k=1:maxite
for i=1:n
x(i)=v(i);
end
for i=1:n
s=0;
for j=1:n
if j~=i
s=s+a(i,j)*x(j);
end
end
v(i)=(b(i)-s)/a(i,i);
x(i)=v(i);
end
for t=1:n
cad2=sprintf('x%d=%10.8f',t,x(t));
cad1=[cad1,cad2];
end
end
set(handles.edit5,'string',cad1);
NO LINEAL
INTERPOLACION
Nos centraremos ahora en el problema de obtener, a partir de una tabla de parejas ( x,f(x))
definida en un cierto intervalo [a,b], el valor de la funcin para cualquier xperteneciente a dicho
intervalo.
x x0 x1 x2 xn
y y0 y1 y2 yn
El objetivo es encontrar una funcin continua lo ms sencilla posible tal que
f(xi) = yi (11)
Se dice entonces que la funcin f(x) definida por la ecuacin (11) es una funcin de
interpolacin de los datos representados en la tabla.
Existen muchas formas de definir las funciones de interpolacin, lo que da origen a un gran
nmero de mtodos (polinomios de interpolacin de Newton, interpolacin de Lagrange,
interpolacin de Hermite, etc). Sin embargo, nos centraremos exclusivamente en dos funciones
de interpolacin:
INICIO
X, ai , bi, n
i = 1, n - 1, 1
a(i)<= X <=a(i+1)
y=b(i)+(((x-a(i))*(b(i+1)-b(i)))/(a(i+1)-a(i)))
i=n
FIN
PROGRAMACION
global a x y
x=str2num(get(handles.edit1,'string'));
y=str2num(get(handles.edit2,'string'));
m=length(x);%tamao del vector x%
n=str2num(get(handles.edit3,'string'));
for j=1:n+1
for k=1:n+1
s1=0;
for i=1:m
s1=s1+(x(i)^(j+k-2));
end
A(j,k)=s1;
End
End
for j=1:n+1
s2=0;
for i=1:n
s2=0;
for i=1:m
s2=s2+(y(i)*(x(i)^(j-1)));
end
B(j)=s2;
end
end
B=B';
a=inv(A)*B;
a=a';
set(handles.edit4,'string',num2str(a));
global a x y
a=fliplr(a);%cambia de orden
b=min(x):0.1:max(x);%intervalo para el grafico
p=polyval(a,b);
plot(x,y,'or',b,p),grid on
xlabel('Coordenadas X');
ylabel('Coordenadas Y');
title('REGRECION POLINOMIAL');
zoom on
CAPITULO IV
DIFERENCIACION E INTEGRACION NUMERICA
TEORIA:
Si empleamos polinomios de grado n=1 y tomamos como nudos x0=a y x1=b, tenemos el caso
ms sencillo posible, en donde los polinomios de interpolacin son:
por lo que:
Esta expresin se conoce como regla del trapecio y proporciona un resultado exacto para
todas las funciones de grado menor o igual a 1.
DIAGRAMA DE FLUJO:
Leer
f(x), a, b, n
h=(b-a)
n
s = f(a) f(b)
i = 1, n-1, 1
Xi = a + i*h
s = s + 2*f(xi)
AREA = S*h/2
Escrbir
AREA
FIN
PROGRAMACION
f=inline(get(handles.edit1,'string'));
a=str2double(get(handles.edit2,'string'));
b=str2double(get(handles.edit3,'string'));
n=str2double(get(handles.edit4,'string'));
h=(b-a)/n;
x(1)=a;
s=0;
for i=1:n
x(i+1)=x(1)+i*h;
s=s+f(x(i))+f(x(i+1));
end
A=s*(h/2);
set(handles.edit5,'string',A);
PARTE GRAFICA
f=inline(get(handles.edit1,'string'));
a=str2double(get(handles.edit2,'string'));
b=str2double(get(handles.edit3,'string'));
n=str2double(get(handles.edit4,'string'));
h=(b-a)/n;
s=f(a)+f(b);
for i=1:n+1
x(i)=a+((i-1)*h);
y(i)=f(x(i));
end
x=[x,b,a,a];
y=[y,0,0,f(a)];
fill(x,y,[0.8 0.4 0.9]);
for i=1:n+1
x(i)=a+((i-1)*h);
y(i)=f(x(i));
line([x(i),x(i)],[0,f(x(i))]);
end
hold on
ezplot(f,[min(x):0.2:max(x)])
hold off
REGLA DE SIMPSON DE1/3:
TEORIA:
(14)
que es exacta para todos los polinomios de grado 2 y curiosamente, exacta para todos los
polinomios de grado 3.
en donde
h = (b-a)/n
(15)
INICIO
LEER
F(x),a,b,n
h=b-a
n
i=0,n,1
xi=a+h
n par
S=0
i=2,n,1
S=S+F(xi-2)+4F(xi-1)+F(xi)
I=S*h/3
ESCRIBIR
I
FIN
PROGRAMACION
f=inline(get(handles.edit1,'string'));
a=str2double(get(handles.edit2,'string'));
b=str2double(get(handles.edit3,'string'));
n=str2double(get(handles.edit4,'string'));
h=(b-a)/n;
s=f(a)+f(b);
for i=1:n+1
x(i)=a+(i-1)*h;
end
if rem(n,2)==0
s=0;
for i=3:2:n+1
s=s+f(x(i-2))+4*f(x(i-1))+f(x(i))
end
I=(h/3)*s
set(handles.edit5,'string',I);
end
f=inline(get(handles.edit1,'string'));
a=str2double(get(handles.edit2,'string'));
b=str2double(get(handles.edit3,'string'));
n=str2double(get(handles.edit4,'string'));
h=(b-a)/n;
s=f(a)+f(b);
for i=1:n+1
x(i)=a+((i-1)*h);
y(i)=f(x(i));
end
x=[x,b,a,a];
y=[y,0,0,f(a)];
fill(x,y,[0.8 0.4 0.9]);
for i=1:n+1
x(i)=a+((i-1)*h);
y(i)=f(x(i));
line([x(i),x(i)],[0,f(x(i))]);
end
hold on
ezplot(f,[min(x):0.2:max(x)])
grid on
REGLA DE SIMPSON DE 3/8:
DIAGRAMA DE FLUJO:
INICIO
S=0
LEER
F(x),a,b,n
n=3
i=3,n,3
ESCRIBIR
n debe ser
mltiplo de
tres
S=S+3/8*h*[ F(xi-3)+3F(xi-2)+3F(xi-1)+F(xi)]
ESCRIBIR
S
FIN
PROGRAMACION
f=inline(get(handles.edit1,'string'));
a=str2double(get(handles.edit2,'string'));
b=str2double(get(handles.edit3,'string'));
n=str2double(get(handles.edit4,'string'));
h=(b-a)/n
x1=a
for i=1:n
x(i+1)=x1+(i*h)
end
if rem(n,3)==0
s=0
for i=3:3:n+1
s=s+f(x(i-2))+3*f(x(i-1))+3*f(x(i))+f(x(i+1))
end
I=((3/8)*h)*s
set(handles.edit5,'string',I)
end
PARTE GRAFICA
f=inline(get(handles.edit1,'string'));
a=str2double(get(handles.edit2,'string'));
b=str2double(get(handles.edit3,'string'));
n=str2double(get(handles.edit4,'string'));
h=(b-a)/n;
s=f(a)+f(b)
for i=1:n+1
x(i)=a+((i-1)*h)
y(i)=f(x(i));
end
x=[x,b,a,a]
y=[y,0,0,f(a)]
fill(x,y,[0.6 0.8 0.4])
for i=1:n+1
x(i)=a+((i-1)*h)
y(i)=f(x(i));
line([x(i),x(i)],[0,f(x(i))])
end
hold on
ezplot(f,[min(x):0.2:max(x)]);
hold off
CAPITULO V
METODO DE EULER:
LEER
F(x,y),a,b,n,y0
x0=a
h=b-a
n
i=1,n,1
y1=y0+h0*f(x)
Y0=y1
x1=x0+h
x0=x1
ESCRIBIR
y0
FIN
PROGRAMACION
f1=inline(get(handles.edit1,'string'));
x0=str2double(get(handles.edit2,'string'));
y0=str2double(get(handles.edit3,'string'));
n=str2double(get(handles.edit4,'string'));
b=str2double(get(handles.edit5,'string'));
h=(b-x0)/n;
for i=1:n
y0=y0+h*f1(x0,y0);
x0=x0+h;
end
set(handles.edit6,'string',y0);
ezmesh(f1);
grid on
zoom on
METODO RUNGE KUTTA
donde
i = 1,...,e
con aij,bi,ci constantes propias del esquema numrico. Los esquemas Runge-Kutta pueden ser
explcitos o implcitos dependiendo de las constantes aij del esquema. Si esta matriz es triangular
inferior con todos los elementos de la diagonal principal iguales a cero; es decir, aij = 0 para j =
i,...,e, los esquemas son explcitos.
Fn = k1 = F(un;tn)
Existen variantes del mtodo de Runge-Kutta clsico, tambin llamado Runge-Kutta explcito,
tales como la versin implcita del procedimiento o las parejas de mtodos Runge-Kutta (o
mtodos Runge-Kutta-Fehlberg).
LEER
F(x), X0,Y0,b, n
h=b-X0
n
i=1,n,1
Y1=Y0-h/6*(K1+2*K2+2*K3+K4)
X1=X0+h
X0=X1
Y0=Y1
ESCRIBIR
Y0
FIN
PROGRAMACION
f1=get(handles.edit1,'string');
f=inline(f1,'x','y');
a=str2double(get(handles.edit2,'string'));
b=str2double(get(handles.edit3,'string'));
n=str2double(get(handles.edit4,'string'));
y0=str2double(get(handles.edit5,'string'));
x0=a;
h=(b-a)/n;
for i=1:n
k1=f(x0,y0);
k2=f(x0+h/2,y0+(h/2)*k1);
k3=f(x0+h/2,y0+(h/2)*k2);
k4=f(x0+h,y0+h*k3);
y1=y0+h*(k1+2*k2+2*k3+k4)/6;
x1=x0+h;
x0=x1;
y0=y1;
Y(i)=y1;
end
set(handles.edit6,'string',y1);
f1=get(handles.edit1,'string');
f=inline(f1,'x','y');
ezmesh(f);
grid on
zoom on