Documentos de Académico
Documentos de Profesional
Documentos de Cultura
2012
| Clculo numrico
1
INTRODUCCIN
Tanto la ciencia y la tecnologa nos describen los fenmenos reales mediante modelos
matemticos. El estudio de estos modelos permite un conocimiento ms profundo del
fenmeno, as como de su evolucin futura.
Desafortunadamente, no siempre es posible aplicar mtodos analticos clsicos por
diferentes razones: La solucin formal es tan complicada que hace imposible cualquier
interpretacin posterior; simplemente no existen mtodos analticos capaces de
proporcionar soluciones al problema; no se adecuan al modelo concreto; o su
aplicacin resulta excesivamente compleja.
Para este tipos de casos son tiles las tcnicas numricas, que mediante una labor de
clculo ms o menos intensa, conducen a soluciones aproximadas que son siempre
numricos.
La importante del clculo radica en que implica la mayora de estos mtodos hacen
que su uso est ntimamente ligado al empleo de computadores, que mediante la
programacin nos permite la solucin de problemas matemticos.
Para la realizacin de este trabajo se utiliz el programa MATLAB.
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
2
CAPITULO I:
CLCULO DE RACES DE ECUACIONES
1. MTODO DE LA BISECCIN:
1.1. TEORA:
En matemticas, el mtodo de biseccin es un algoritmo de bsqueda de
races que trabaja dividiendo el intervalo a la mitad y seleccionando el
subintervalo que tiene la raz.
PROCEDIMIENTO:
- Elija valores Iniciales para a y b de forma tal que lea funcin
cambie de signo sobre el intervalo. Esto se puede verificar
asegurndose de que :
- La primera aproximacin a la raz se determina con la frmula:
- Realizar las siguientes evaluaciones para determinar en que
subintervalo se encuentra la raz:
< 0 Entonces
Entonces
Entonces
Es la Raz
- Calcule la nueva aproximacin:
- Evaluar la aproximacin relativa:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
3
No. (Falso) Repetir el paso 3, 4 y 5
S. (Verdadero) Entonces
Es la Raz
1.2. DIAGRAMA DE FLUJO:
Inicio
f(x), a,
b, E
F(a)*f(b)<0
v
| b-a|>E
Xap=(a+b)/2
f(a)*f(Xap)=0 V
a = b
F
f(a)*f(Xap)<0
V
b = Xap
F
a = Xap
Xap
F
No
existe
la raz
FIN
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
4
1.3. CDIGO DE PROGRAMA:
CDIGO EN EL BOTON CALCULAR:
f=get(handles.edit1,'string');
f=inline(f);
a=str2double(get(handles.edit2,'string'));
b=str2double(get(handles.edit3,'string'));
E=str2double(get(handles.edit4,'string'));
if f(a)*f(b)< 0
while abs(b-a)>E
x=(a+b)/2;
if f(a)*f(x)==0
a=b;
else
if f(a)*f(x)<0
b=x;
else
a=x;
end
end
set(handles.edit5,'string',x);
end
else
set(handles.edit5,'string','No existe la raiz en el intervalo');
end
CDIGO EN EL BOTN GRAFICAR:
function varargout = pushbutton2_Callback(h, eventdata, handles,
varargin)
f=get(handles.edit1,'string');
f=inline(f);
ezplot(f), grid on
CDIGO EN EL BOTN SALIR:
function pushbutton6_Callback(hObject, eventdata, handles)
close
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
5
1.4. VENTANA DE DISEO Y APLICACIN:
2. MTODO DEL PUNTO FIJO:
2.1. TEORA:
Dada la ecuacin , el mtodo de las aproximaciones sucesivas
reemplaza esta ecuacin por una equivalente, , definida en la
forma Para encontrar la solucin, partimos de un valor
inicial y calculamos una nueva aproximacin
Reemplazamos el nuevo valor obtenido y repetimos el proceso. Esto da
lugar a una sucesin de valores, {
2.2. DIAGRAMA DE FLUJO:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
7
2.3. CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
function varargout = pushbutton2_Callback(h, eventdata, handles,
varargin)
f=get(handles.edit15,'string');
g=inline(f)
a=str2double(get(handles.edit9,'string'));
E=str2double(get(handles.edit11,'string'));
n=str2double(get(handles.edit17,'string'));
x1=g(a)
k=1;
cadena1=sprintf('a = %8.6f valor inicial\n',a);
while abs(x1-a)>E&k<n
a=x1
x1=g(a)
k=k+1
cadena2=sprintf('x%d = %8.6f\n',k-1,x1);
Inicio
f(x), g(x),
X0, E
X1=g(X0)
|X0-X1| >E
X0 = X1
X1 = g(X0)
X1
FIN
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
8
cadena1=[cadena1,cadena2];
end
CDIGO EN EL BOTN GRAFICAR:
function varargout = pushbutton1_Callback(h, eventdata, handles,
varargin)
funcionf=get(handles.edit1,'string');
f=inline(funcionf);
figure(1);
ezplot(f),grid on
CDIGO EN EL BOTN SALIR:
function pushbutton6_Callback(hObject, eventdata, handles)
close
2.4. VENTANA DE DISEO Y APLICACIN:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
9
3. MTODO DE NEWTON RAPHSON:
3.1. TEORA:
Este mtodo parte de una aproximacin inicial
y obtiene una
aproximacin mejor,
Este mtodo est definido por el denominador hace que
geomtricamente se base en una aproximacin a una recta tangente a la
curva trazada en el punto correspondiente a la aproximacin
presente, esto puede observarse en la figura:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
10
3.2. DIAGRAMA DE FLUJO CON LA DERIVADA:
Inicio
f(x), f(x),
X0, E
X1 = X0 - f(X0)/f(X0)
|X1-X0| >E
X0 = X1
X1 = X0 - f(X0) / f(X0)
X1
FIN
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
11
3.3. CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
function varargout = pushbutton1_Callback(h, eventdata, handles,
varargin)
f=get(handles.edit1,'string');
g=get(handles.edit2,'string');
f=inline(f);
g=inline(g);
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.edit5,'string',x1);
CDIGO EN EL BOTN GRAFICAR:
function varargout = pushbutton2_Callback(h, eventdata, handles,
varargin)
f=get(handles.edit1,'string');
f=inline(f);
ezplot(f), grid on
CDIGO EN EL BOTN SALIR:
function pushbutton6_Callback(hObject, eventdata, handles)
close
3.4. VENTANA DE DISEO Y APLICACIN:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
12
3.5. SIN INGRESAR LA DERIVADA: f x DIAGRAMA DE FLUJO:
Inicio
f(x), X0, E
h = 0,00001;
df = [f(X0+h) - f(X0)] / h
|X1-X0| >E
X0 = X1
h = 0,00001
X1
FIN
X1 = X0 - f(X0)/df
X1 = X0 - f(X0)/df
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
13
3.6. CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
function varargout = pushbutton1_Callback(h, eventdata, handles,
varargin)
f=get(handles.edit1,'string');
f=inline(f);
x=str2double(get(handles.edit3,'string'));
E=str2double(get(handles.edit4,'string'));
D=(f(x+0.0001)-f(x))/0.0001;
x1=x-(f(x))/D;
while abs (x1-x)>E
x=x1;
D=(f(x+0.0001)-f(x))/0.0001;
x1=x-(f(x))/D;
end
set(handles.edit5,'string',x1);
CDIGO EN EL BOTN GRAFICAR:
function varargout = pushbutton2_Callback(h, eventdata, handles,
varargin)
f=get(handles.edit1,'string');
f=inline(f);
ezplot(f), grid on
4. MTODO DE LA SECANTE:
4.1. TEORA:
El principal inconveniente del mtodo de Newton estriba en que requiere
conocer el valor de la primera derivada de la funcin en el punto. Sin
embargo, la forma funcional de dificulta en ocasiones el clculo de la
derivada. En estos casos es ms til emplear el mtodo de la secante.
El mtodo de la secante parte de dos puntos (y no slo uno como el mtodo
de Newton) y estima la tangente (es decir, la pendiente de la recta) por una
aproximacin de acuerdo con la expresin:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
14
En general, el mtodo de la secante presenta las mismas ventajas y
limitaciones que el mtodo de Newton-Raphson explicado anteriormente.
4.2. DIAGRAMA DE FLUJO:
4.3. CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
function varargout = pushbutton3_Callback(h, eventdata, handles,
varargin)
f=inline(get(handles.edit1,'string'));
x0=str2double(get(handles.edit2,'string'));
x1=str2double(get(handles.edit3,'string'));
E=str2double(get(handles.edit4,'string'));
while abs(x1-x0)>E
x2=x1-(((x1-x0)*f(x1))/(f(x1)-f(x0)));
Inicio
f(x), X1, X0,
E
|X1-X0| >E
X2 = X1 [f(X1)*(X1-X0)] / [f(X1)-f(X0)]
X0 = X1
X1 = X2
X2
FIN
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
15
x0=x1;
x1=x2;
end
set(handles.edit5,'string',x2)
CDIGO EN EL BOTN GRAFICAR:
function varargout = pushbutton4_Callback(h, eventdata, handles,
varargin)
f=get(handles.edit1,'string');
f=inline(f);
ezplot(f), grid on
CDIGO EN EL BOTN SALIR:
function pushbutton3_Callback(hObject, eventdata, handles)
close(secante)
4.4. VENTANA DE DISEO y APLICACION:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
16
5. MTODO DE LIN:
5.1. TEORA:
Dada la ecuacin donde P tiene la forma:
Sea el factor cuadrtico:
Con lo cual la ecuacin anterior resulta:
Donde es el residuo
Polinomio reducido
Multiplicando
Igualando coeficientes de la misma potencia
. .
En general:
Los residuos estn dados por:
Para que
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
17
Se define:
Si
5.2. DIAGRAMA DE FLUJO:
Entonces
INICIO
LEER
a(i); i=1,2,3...n
p, q, E, n
k=n:1:-1
b(n+1)=0
b(n+2)=0
b(k)=a(k)-p*b(k+1)-q*b(k+2)
i=n:1:-1
c(n+1)=0;
c(n+2)=0;
c(i)=b(i)-p*c(i+1)-q*b(i+2)
P=(b(1)*c(4)-b(2)*c(3))/(c(2)*c(4)-(c(3))^2);
Q=(b(2)*c(2)-b(1)*c(3))/(c(2)*c(4)-(c(3))^2);
P>E & Q>E
p=p+P;
q=q+Q;
k=n:1:-1
b(k)=a(k)-p*b(k+1)-q*b(k+2);
b(n+1)=0;
b(n+2)=0;
i=n:1: -1
c(i)=b(i)-p*c(i+1)-q*b(i+2);
c(n+1)=0;
c(n+2)=0;
P=(b(1)*c(4)-b(2)*c(3))/(c(2)*c(4)-(c(3))^2);
Q=(b(2)*c(2)-b(1)*c(3))/(c(2)*c(4)-(c(3))^2
V
p=p+P;
q=q+Q;
x1=(-p+sqrt(p^2-4*q))/2;
x2=(-p-sqrt(p^2-4*q))/2;
ESCRIBIR
X1, X2
FIN
V
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
18
5.3. CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a=str2num(get(handles.edit1,'string'));
p=str2double(get(handles.edit2,'string'));
q=str2double(get(handles.edit3,'string'));
E=str2double(get(handles.edit4,'string'));
n=length(a);
for k=n:-1:1
b(n+1)=0;
b(n+2)=0;
b(k)=a(k)-p*b(k+1)-q*b(k+2);
end
for i=n:-1:1
c(n+1)=0;
c(n+2)=0;
c(i)=b(i)-p*c(i+1)-q*b(i+2);
end
P=(b(1)*c(4)-b(2)*c(3))/(c(2)*c(4)-(c(3))^2);
Q=(b(2)*c(2)-b(1)*c(3))/(c(2)*c(4)-(c(3))^2);
while P>E & Q>E
p=p+P;
q=q+Q;
for k=n:-1:1
b(k)=a(k)-p*b(k+1)-q*b(k+2);
b(n+1)=0;
b(n+2)=0;
end
for i=n:-1:1
c(i)=b(i)-p*c(i+1)-q*b(i+2);
c(n+1)=0;
c(n+2)=0;
end
P=(b(1)*c(4)-b(2)*c(3))/(c(2)*c(4)-(c(3))^2);
Q=(b(2)*c(2)-b(1)*c(3))/(c(2)*c(4)-(c(3))^2);
end
p=p+P;
q=q+Q;
x1=(-p+sqrt(p^2-4*q))/2;
x2=(-p-sqrt(p^2-4*q))/2;
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
19
set(handles.edit5,'string',x1);
set(handles.edit6,'string',x2);
CDIGO EN EL BOTN CALCULAR:
function pushbutton2_Callback(hObject, eventdata, handles)
close
5.4. VENTANA DE DISEO Y APLICACIN:
CAPITULO II
SISTEMA DE ECUACIN LINEAL
6. MTODO DE GAUSS - JORDAN
6.1. TEORA:
Sea un sistema de ecuaciones lineales de la forma:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
20
{
Se trata de un sistema de n ecuaciones con n incgnitas, x1, x2, ..., xn. Los
elementos aij y bi son nmeros reales fijados.
El sistema de ecuaciones se puede escribir, empleando una muy til
representacin matricial, como:
(
Es decir
Donde A es la matriz de coeficientes, X es el vector incgnitas y B es el vector
trminos independientes.
PROCEDIMIENTO:
Crear la matriz cuyos elementos son los de la matriz A y el vector B. A es la
matriz se le denomina la matriz aumentada.
(
|
|
Matriz aumentada
Mediante transformaciones elementales de filas en la matriz aumentada, los
elementos de la matriz de coeficientes A debe transformarse en la matriz
identidad y los elementos que estn en la posicin del vector de trminos
independientes B, ser la solucin del sistema.
(
|
|
Matriz transformada
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
21
Y las races del sistema de ecuaciones son:
El proceso, requiere de
multiplicaciones y
sumas.
6.2. DIAGRAMA DE FLUJO:
Inicio
Leer
n, aij
i = 0, n, 1
divisor = aii
j = 0, n+1, 1
aij = aij*divisor
k = 0, n, 1
i ~ = k
pivote = a(k, i)
j = 0, n, 1
akj = akj pivote*aij
escribir
ai, n+1
FIN
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
22
6.3. CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
function varargout = pushbutton1_Callback(h, eventdata, handles,
varargin)
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
set(handles.edit2,'string',cadena);
CDIGO EN EL BOTN SALIR:
function varargout = pushbutton3_Callback(h, eventdata, handles,
varargin)
close
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
23
6.4. VENTANA DE DISEO Y APLICACIN:
7. MTODO DE GAUSS SEIDEL
7.1. TEORA:
Mtodo iterativo que su utiliza para resolver sistema de ecuaciones de la
forma:
{
Que matricialmente se puede escribir como A X=B, supongamos que
Despejamos los X
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
24
El proceso se inicia dando un valor inicial para los puntos
se podra usar, por ejemplo la solucin trivial
si
este fuera el caso se tendra que:
Los son los nuevos valores inciales que sern utilizados en
una segunda iteracin.
La convergencia puede definirse mediante
|
Dnde:
raz
: Iteracin actual
: Iteracin anterior
: Tolerancia prefijada
RE ARREGLO DE ECUACIONES
El proceso de gauss - Seidel converge si la matriz coeficientes cada
elemento de la diagonal es el mayor en valor absoluto que la suma de todos
los dems elementos de la misma fila o columna .Es decir se asegura la
convergencia s.
7.2. DIAGRAMA DE FLUJO:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
25
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
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
26
7.3. CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
function varargout = pushbutton1_Callback(h, eventdata, handles,
varargin)
maxite=str2double(get(handles.edit1,'string'));
v=str2num(get(handles.edit2,'string'));
a=str2num(get(handles.edit3,'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
cad2=sprintf('\n',t);
cad1=[cad1,cad2];
end
set(handles.edit5,'string',cad1);
CDIGO EN EL BOTN SALIR:
function varargout = pushbutton3_Callback(h, eventdata, handles,
varargin)
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
27
close(gauusseidel)
7.4. VENTANA DE DISEO Y APLICACIN:
INTERPOLACIN
8. INTERPOLACIN LINEAL:
8.1. TEORA:
Nos centraremos ahora en el problema de obtener, a partir de una tabla de
parejas definida en un cierto intervalo el valor de la funcin
para cualquier x perteneciente a dicho intervalo.
Supongamos que disponemos de las siguientes parejas de datos:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
28
x x0 x1 x2 xn
y y0 y1 y2
El objetivo es encontrar una funcin continua lo ms sencilla posible tal que:
Se dice entonces que la funcin definida por la ecuacin 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:
- Los polinomios de interpolacin de Lagrange.
- Las funciones de interpolacin splines. Estas funciones son
especialmente importantes debido a su idoneidad en los clculos
realizados con ordenador.
8.2. DIAGRAMA DE FLUJO:
Inicio
Leer
X, ai, bi, n
i = 1, n-1, 1
ai <= X <= a(i+1)
y = b(i)+(((X+a(i))*(b(i))) / (a(i+1)-a(i)))
i = n
Escribir
y
FIN
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
29
8.3. CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
function varargout = togglebutton3_Callback(h, eventdata, handles,
varargin)
a=str2num(get(handles.edit1,'string'));
b=str2num(get(handles.edit2,'string'));
x=str2double(get(handles.edit3,'string'));
n=length(a);
for i=1:n-1
if x>=a(i) & x<=a(i+1)
y = b(i)+(((x-a(i))*(b(i+1)-b(i)))/(a(i+1)-a(i)));
i=n;
end
end
set(handles.edit4,'string',y);
CDIGO EN EL BOTN SALIR:
function varargout = pushbutton3_Callback(h, eventdata, handles,
varargin)
close(interpolacionlineal)
8.4. VENTANA DE DISEO Y APLICACIN:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
30
INTERPOLACIN POLINMICA
9. POLINOMIO DE LAGRANGE:
9.1. TEORA:
Si
para cada
k=0, 1,2n.
Este polinomio est dado por:
Dnde:
Para un polinomio lineal la aproximacin es:
Dnde:
Entonces:
(
Para un polinomio de segundo grado est dado por:
Dnde:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
31
) (
) (
) (
)
Entonces el polinomio para segundo grado es:
(
) (
) (
) (
Donde x es el valor a interpolar.
9.2. DIAGRAMA DE FLUJO:
INICIO
Leer
y(i), x(i) a, x
S = 0
K = 1, n, 1
N = 1
D = 1
i = 1, n, 1
i ~ = k
N = N(x-x(i))
D = D(x(k)-x(i))
L = N/D
S =
S+L(x)*Y(k)
Escribir
Y0
FIN
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
32
9.3. CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
function pushbutton1_Callback(hObject, eventdata, handles)
f=inline(get(handles.edit2,'string'));
x=str2double(get(handles.edit3,'string'));
n=length(X);
s=0;
for k=1:1:n
NUM=1;
DEN=1;
for i=1:1:n
if i~=k
NUM=NUM*(x-X(i));
DEN=DEN*(X(k)-X(i));
end
L(k)=NUM/DEN;
end reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
s=s+(L(k)*f(X(k)));
end
set(handles.edit4,'string',s);
CDIGO EN EL BOTN GRAFICAR:
function pushbutton3_Callback(hObject, eventdata, handles)
f=inline(get(handles.edit2,'string'));
ezplot(f),grid on
CDIGO EN EL BOTN SALIR:
function varargout = pushbutton3_Callback(h, eventdata, handles,
varargin)
close(polinomiolagrange)
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
33
9.4. VENTANA DE DISEO Y APLICACIN:
AJUSTES POLINOMIALES
10. REGRESIN POLINOMIAL :
10.1. TEORA:
Supongamos que se conocen los datos o o 1 1 n n con
0 1 nmeros reales distintos, y se desea encontrar un polinomio:
Tal que:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
34
Sea mnima.
El grado m del polinomio m se puede escoger previamente con base en
algn resultado terico, alguna expectativa o por la aplicacin que se le
pretenda dar al polinomio En cualquier caso estamos libres de elegir el
grado que parezca mejor. En muchos casos el grado ser uno y el polinomio
obtenido se llamar la recta que mejor se ajusta o la recta de mnimos
cuadrados para la tabla de datos.
Volviendo a la funcin 0 1 m una condicin necesaria para la
existencia de un mnimo relativo de esta funcin es que las derivadas
parciales de 0 1 m con respecto a j, sean cero.
Resultan entonces las siguientes m+1 ecuaciones lineales en las incgnitas
0 1 m:
Si en las ecuaciones anteriores cancelamos el 2, desarrollamos los parntesis
y usamos que
( ) ( ) ( )
2
n
0 k
k
m
k m
2
k 2 k 1 0
2
n
0 k
k k m m 1 0
y x a ,....., x a x a a y x p ) a ,....., a , S(a
= =
+ + + = =
( )
( )( )
( )( )
( )( )
( )( ) 0 x y x a ..... x a x a a 2
a
S
.. ..........
0 x y x a ..... x a x a a 2
a
S
..........
0 x y x a ..... x a x a a 2
a
S
0 x y x a ..... x a x a a 2
a
S
0 y x a ..... x a x a a 2
a
S
m
k k
m
k m
2
k 2 k 1 0
n
0 k
m
j
k k
m
k m
2
k 2 k 1 0
n
0 k
j
2
k k
m
k m
2
k 2 k 1 0
n
0 k
2
k k
m
k m
2
k 2 k 1 0
n
0 k
1
k
m
k m
2
k 2 k 1 0
n
0 k
0
= + + + + =
c
c
= + + + + =
c
c
= + + + + =
c
c
= + + + + =
c
c
= + + + + =
c
c
=
=
=
=
=
( )
0
n
0 k
0
a 1 n a + =
=
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
35
Obtenemos:
Este es un SEL de m+1 ecuaciones lineales en las m+1 incgnitas a0, a1
am, que se llama Sistema de Ecuaciones Normales. Este sistema de ecuaciones
normales se puede escribir en forma simplificada como sigue:
Estas ecuaciones se pueden reproducir a partir de:
Multiplicando a ambos lados por
Sumando sobre k
10.2. DIAGRAMA DE FLUJO:
( )
|
.
|
\
|
= |
.
|
\
|
+ + |
.
|
\
|
+ |
.
|
\
|
+ |
.
|
\
|
|
.
|
\
|
= |
.
|
\
|
+ + |
.
|
\
|
+ |
.
|
\
|
+ |
.
|
\
|
|
.
|
\
|
= |
.
|
\
|
+ + |
.
|
\
|
+ |
.
|
\
|
+ |
.
|
\
|
|
.
|
\
|
= |
.
|
\
|
+ + |
.
|
\
|
+ |
.
|
\
|
+ |
.
|
\
|
|
.
|
\
|
= |
.
|
\
|
+ + |
.
|
\
|
+ |
.
|
\
|
+ +
= =
+
=
+
=
+
=
= =
+
=
+
=
+
=
= =
+
= = =
= =
+
= = =
= = = =
n
0 k
k
m
k m
n
0 k
m m
k 2
n
0 k
m 2
k 1
n
0 k
m 1
k 0
n
0 k
m
k
n
0 k
k
j
k m
n
0 k
j m
k 2
n
0 k
j 2
k 1
n
0 k
j 1
k 0
n
0 k
j
k
n
0 k
k
2
k m
n
0 k
2 m
k 2
n
0 k
4
k 1
n
0 k
3
k 0
n
0 k
2
k
n
0 k
k k m
n
0 k
1 m
k 2
n
0 k
3
k 1
n
0 k
2
k 0
n
0 k
k
n
0 k
k m
n
0 k
m
k 2
n
0 k
2
k 1
n
0 k
k 0
y x a x ..... a x a x a x
:::
y x a x ..... a x a x a x
... ...
.
.
y x a x ..... a x a x a x
y x a x ..... a x a x a x
y a x ..... a x a x a 1 n
m 0,1,....,. j con y x x a
n
0 k
k
j
k
n
0 k
j i
k
m
0 i
i
= =
= =
+
=
( )
k
m
k m
2
k 2 k 1 0 k m
y x a ,....., x a x a a x p = + + + =
k
j
k
j m
k m
j 2
k 2
j 1
k 1
j
k 0
j
k k
j
k
m
k m
j
k
2
k 2
j
k k 1
j
k 0
y x x a ,....., x a x a x a
x y x x a ,....., x x a x x a x a
= + + +
= + + +
+ + +
m ., 0,1,2,.... j con y x x a ..... x a x a x a
m
0 k
k
j
k
m
0 k
j m
k m
n
0 k
j 2
k 2
n
0 k
j 1
k 1
n
0 k
j
k 0
= = + + + +
= =
+
=
+
=
+
=
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
36
10.3. CDIGO DE PROGRAMA:
CDIGO EN EL BOTN ACEPTAR:
function pushbutton1_Callback(hObject, eventdata, handles)
m=str2double(get(handles.edit1,'string'));
x=str2num(get(handles.edit2,'string'));
y=str2num(get(handles.edit3,'string'));
A11=0;
A12=0;
A22=m;
B1=0;
Inicio
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)
A22 = 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
FIN
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
37
B2=0;
for i=1:m
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)-(A12*A21));
b=((B2*A11)-(B1*A21))/((A11*A22)-(A12*A21));
ard=sprintf('y = %6.4fx + %6.4f',a,b);
set(handles.edit4,'string',ard);
CDIGO EN EL BOTN GRAFICAR:
function pushbutton2_Callback(hObject, eventdata, handles)
figure(1);
xx=min(x)-1:0.2:max(x)+1;
yy=a*xx+b;
ezplot(x,y,'or',xx,yy),grid on
10.4. VENTANA DE DISEO Y APLICACION:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
38
CAPITULO - III
INTEGRACIN NUMRICA
11. REGLA DEL TRAPECIO:
11.1. TEORA:
Este mtodo resulta de sustituir la funcin por un polinomio
de primer grado
en
al polinomio
se le puede representar mediante un polinomio se le puede
representar mediante un polinomio de Lagrange, es decir:
Resolviendo:
Generalizando:
Aplicando la regla del trapecio a c/u de las integrales se tiene:
lim
11.2. DIAGRAMA DE FLUJO:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
39
11.3. CDIGO DE PROGRAMA:
CDIGO EN EL BOTN ACEPTAR:
function varargout = pushbutton4_Callback(h, eventdata, handles,
varargin)
f=inline(get(handles.edit1,'string'));
a=str2num(get(handles.edit2,'string'));
b=str2num(get(handles.edit3,'string'));
n=str2double(get(handles.edit4,'string'));
h=(b-a)/n;
s=f(a)+f(b);
for i=2:n
x(i)=a+(i-1)*h;
s=s+2*f(x(i));
end
I=s*(h/2);
set(handles.edit5,'string',I);
CDIGO EN EL BOTN GRAFICAR:
Inicio
Leer
f(X), a, b, n
h = (a+b) / n
S = f(a) - f(b)
i = 1, n-1, 1
Xi = a +i*h
S = S +2*f(Xi)
AREA = S*h/2
Escribir
AREA
FIN
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
40
function varargout = pushbutton5_Callback(h, eventdata, handles,
varargin)
f=inline(get(handles.edit1,'string'));
a=str2num(get(handles.edit2,'string'));
b=str2num(get(handles.edit3,'string'));
n=str2double(get(handles.edit4,'string'));
h=(b-a)/n;
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.8 0.9])
for i=1:n+1
x(i)=a+(i-1)*h;
y(i)=f(x(i));
end
hold on
ezplot(f,[min(x):0.2:max(x)])
plot(x,y,'og')
plot(x,y,'g')
CDIGO EN EL BOTN SALIR:
function varargout = pushbutton3_Callback(h, eventdata, handles,
varargin)
close(trapecio)
11.4. VENTANA DE DISEO Y APLICACION:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
41
12. REGLA DE SIMPSON 1/3:
12.1. TEORA:
La regla de Simpson de 1/3 resulta cuando se sustituye la funcin y=f(x)
por un polinomio de segundo grado es decir:
En el intervalo
[(
) (
) (
) (
Resolviendo la integral se obtiene:
GENERALIZANDO PARA ''n'' INTERVALOS
Los intervalos se toman de dos en dos:
Aplicando la regla de Simpson de 1/3 para cada integral de tiene:
Dnde:
12.2. DIAGRAMA DE FLUJO:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
42
12.3. CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
function varargout = pushbutton1_Callback(h, eventdata, handles,
varargin)
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;
Inicio
Leer
f(X), a, b, n
h = (a+b) / 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
AREA
FIN
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
43
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
CDIGO EN EL BOTN GRAFICAR:
function varargout = pushbutton2_Callback(h, eventdata, handles,
varargin)
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)])
CDIGO EN EL BOTN SALIR:
function varargout = pushbutton3_Callback(h, eventdata, handles, varargin)
close(sinpson1/3)
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
44
12.4. VENTANA DE DISEO Y APLICACIN:
13. REGLA DE SIMPSON DE 3/8:
13.1. TEORA:
La regla de Simpson de 3/8 resulta cuando se sustituye la funcin
por un polinomio de tercer grado es decir:
En el intervalo
Resolviendo la integral se obtiene:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
45
13.2. DIAGRAMA DE FLUJO:
13.3. CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
function varargout = pushbutton3_Callback(h, eventdata, handles,
varargin)
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
for i=1:n+1
x(i)=a+(i-1)*h
Inicio
Leer
f(X), a, b, n
S = 0
h = (a+b) / n
n = 3
i = 3, n, 3
S = S +3/8*h* [f(Xi-3) + 3f(Xi-1) + 3f(Xi-1)+f(Xi)
Escribir
S
Escribir
n debe ser mltiplo de
tres
FIN
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
46
end
if rem(n,3)==0
s=0
for i=3:n+1:3
s=s+f(x(i-2))+3*f(x(i-1))+3*f(x(i))+f(x(i-1))
end
I=((3*h)/8)*s;
set(handles.edit5,'string',I)
end
CDIGO EN EL BOTN GRAFICAR:
function varargout = pushbutton4_Callback(h, eventdata, handles,
varargin)
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)]);
CDIGO EN EL BOTN SALIR:
function pushbutton5_Callback(hObject, eventdata, handles)
close
13.4. VENTANA DE DISEO Y APLICACIN:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
47
14. INTEGRALES MLTIPLES
14.1. TEORA:
Para el clculo de integrales de funciones de varia variables se pueden
usar las reglas ya estudiadas como la regla del trapecio, regla de Simpson
1/3 y 3/8 son tiles para resolver integrales dobles y triples.
En esta ocasin usaremos Simpson de 1/3 para el clculo de una integral
doble de la forma:
Dnde:
{ }
{ }
Para aproximar la solucin de la integral
Utilizando la regla de Simpson 1/3
Por lo tanto:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
48
Dnde:
14.2. DIAGRAMA DE FLUJO
INICIO
LEER
f(x,y), g1(x), g2(x), a, b
h=(b-a)/2
x0=a
s=0
i=1:3
h2=(g2(x0)-g1(x0))/2
w(i)=(h2/3)*(f((x0),g1(x0))+4*f(x0,g1(x0)+h2)+f(x0,g2(x0)))
x0=x0+h
I=(h/3)*(w(1)+4*w(2)+w(3))
ESCRIBIR
I
FIN
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
49
14.3. CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
f=inline(get(handles.edit1,'string'),'x','y');
g1=inline(get(handles.edit2,'string'));
g2=inline(get(handles.edit3,'string'));
a=str2double(get(handles.edit4,'string'));
b=str2double(get(handles.edit5,'string'));
h=(b-a)/2;
x0=a;
s=0;
for i=1:3
h2=(g2(x0)-g1(x0))/2;
w(i)=(h2/3)*(f((x0),g1(x0))+4*f(x0,g1(x0)+h2)+f(x0,g2(x0)));
x0=x0+h;
end
I=(h/3)*(w(1)+4*w(2)+w(3));
set(handles.edit6,'string',I);
CDIGO EN EL BOTN GRAFICAR:
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
f=get(handles.edit1,'string');
f1=inline(f,'x','y');
ezmesh(f1);
grid on
CDIGO EN EL BOTN SALIR:
function pushbutton5_Callback(hObject, eventdata, handles)
close
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
50
14.4. VENTANA DE DISEO Y APLICACIN:
CAPITULO - IV
ECUACIONES DIFERENCIALES ORDINARIAS
15. METODO DE EULER:
15.1. TEORA:
Este mtodo consiste en dividir el intervalo en n subintervalos de
longitud 'h';
donde
la condicin
inicial
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
51
FORMULA DE EULER
Es decir, se genera una sucesin de aproximacin:
15.2. DIAGRAMA DE FLUJO:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
52
15.3. CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
function varargout = pushbutton1_Callback(h, eventdata, handles,
varargin)
f1=get(handles.edit1,'string'); f=inline(f1,'x','y');
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*f(x0,y0);
Inicio
Leer
f(X, Y), a, b, n, 0
h = (a+b) / n
i = 1, n, 1
Y1 = Y0 + h0*f(x)
Y0 = Y1
X1 = X0 + h
X0 = x1
Escribir
Y0
FIN
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
53
x0=x0+h;
end
set(handles.edit6,'string',y0);
CDIGO EN EL BOTN ITERACIONES:
function varargout = pushbutton6_Callback(h, eventdata, handles,
varargin)
f1=get(handles.edit1,'string'); f=inline(f1,'x','y');
x(1)=str2double(get(handles.edit2,'string'));
y(1)=str2double(get(handles.edit3,'string'));
n=str2double(get(handles.edit4,'string'));
b=str2double(get(handles.edit5,'string'));
h=(b-x(1))/n;
cad1=sprintf('Iter. x %d. %8.4f %8.4f\n',1,x(1),y(1));
for i=1:n
y(i+1)=y(i)+h*f(x(i),y(i));
x(i+1)=x(i)+h;
cad2=sprintf('%d. %8.4f %8.4f\n',i+1,x(i+1),y(i+1));
cad1=[cad1,cad2];
end
set(handles.edit7,'string',cad1);
CDIGO EN EL BOTN GRAFICAR:
function varargout = pushbutton2_Callback(h, eventdata, handles,
varargin)
f1=get(handles.edit1,'string');
f=inline(f1,'x','y');
ezmesh(f);
grid on
CDIGO EN EL BOTN SALIR:
function pushbutton7_Callback(hObject, eventdata, handles)
close
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
54
15.4. VENTANA DE DISEO Y APLICACIN:
16. METODO RUNGE KUTTA DE CUARTO ORDEN :
16.1. TEORA:
El mtodo de Runge-Kutta es un mtodo genrico de resolucin numrica
de ecuaciones diferenciales. Este conjunto de mtodos fue desarrollado
alrededor del ao 1900 por los matemticos C. Runge y M. W. Kutta.
Este mtodo puede ser usado para resolver un nmero grande de
ecuaciones diferenciales.
Dada la ecuacin diferencial ordinaria
con condiciones
iniciales
Para aplicar la regla de Simpson de 1/3 a
se le dividi en dos
intervalos es decir:
Entonces
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
55
]
Al trmino
) se le expresa como:
)
para aproximar la pendiente de
) en el punto promedio (
]
Pero
Por EULER se tiene que:
Hacemos cambios de variables:
Hagamos
entonces
Hagamos
) entonces
) por
euler : (
entonces
)
Hagamos
) entonces
) por
euler (
entonces:
)
Hagamos
entonces
) por
euler
) entonces:
Por lo tanto:
Dnde:
16.2. DIAGRAMA DE FLUJO:
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
56
16.3. CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
function varargout = pushbutton1_Callback(h, eventdata, handles,
varargin)
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);
Inicio
Leer
f(X), Xo, Yo, b, n
h = (a+b) / n
i = 1, n, 1
K1 = f(Xo, Yo)
K2 = f(Xo+h/2, Yo+h/2*K1)
K3 = f(Xo+h/2, Yo+h/2*K2)
K4 = f(Xo+h, Yo+h*K3)
Y1 = Yo (h/6)*(K1+ 2*K2+2*K3+K4)
X1 = Xo +h
Xo = X1
Yo = Y1
Escribir
Yo
FIN
Universidad Nacional "JORGE BASADRE GROHMANN"
2012
| Clculo numrico
57
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;
end
set (handles.edit6,'string',y1);
CDIGO EN EL BOTN GRAFICAR:
function pushbutton6_Callback(hObject, eventdata, handles)
f1=get(handles.edit1,'string');
f=inline(f1,'x','y');
ezmesh(f);
grid on
CDIGO EN EL BOTN SALIR:
function varargout = pushbutton2_Callback(h, eventdata, handles,
varargin)
close(kutta1)
16.4. VENTANA DE DISEO Y APLICACIN: