You are on page 1of 57

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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.

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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 :
() () < 0

La primera aproximacin a la raz se determina con la frmula:


= ( + ) / 2

Realizar las siguientes evaluaciones para determinar en que


subintervalo se encuentra la raz:
() ( ) < 0 Entonces =
() () > 0 Entonces =
() () = 0 Entonces Es la Raz

Calcule la nueva aproximacin:


+ 1 = ( + ) / 2

Evaluar la aproximacin relativa:

| ( + 1 ) / + 1 | <
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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

| b-a|>E

Xap=(a+b)/2

f(a)*f(Xap)=0

a=b

No
existe
la raz

f(a)*f(Xap)<0

a = Xap

b = Xap

Xap

3
FIN

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

1.4. VENTANA DE DISEO Y APLICACIN:

2. MTODO DEL PUNTO FIJO:


2.1.

TEORA:
Dada la ecuacin () = 0, 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 0 y calculamos una nueva aproximacin 1 = (0).
Reemplazamos el nuevo valor obtenido y repetimos el proceso. Esto da lugar
a una sucesin de valores, {0 , 1,, } que si converge, tendr como lmite
la
solucin
del
problema.
5
En la figura se representa la interpretacin geomtrica del mtodo. Partimos
de un punto inicial x0 y calculamos = (0). La interseccin de esta
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

solucin con la recta = nos dar un nuevo valor 1 ms prximo a la


solucin final.
Sin embargo, el mtodo puede divergir fcilmente. Es fcil comprobar que el
mtodo slo podr converger si la derivada () es menor en valor absoluto
que la unidad (que es la pendiente de la recta definida por = . Un
ejemplo de este caso se muestra en la figura. Esta condicin, que a priori
puede considerarse una severa restriccin del mtodo, puede obviarse
fcilmente. Para ello basta elegir la funcin () del siguiente modo:
() = + ()
De forma que tomando un valor de adecuado, siempre podemos hacer que
() cumpla la condicin de la derivada.
CONVERGENCIA:
El mtodo de aproximaciones sucesivas converge si | ()| < 1

Co
Convergencia Montona

Divergencia Montona
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

< () <

2012

() >

2.2. DIAGRAMA DE FLUJO:

Inicio
f(x), g(x),
X0, E

X1=g(X0)

|X0-X1| >E

X0 = X1

X1 = g(X0)

X1
FIN

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'));
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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);
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:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

3. MTODO DE NEWTON RAPHSON:


3.1. TEORA:
Este mtodo parte de una aproximacin inicial 0 y obtiene una aproximacin
mejor, 1 , dada por la frmula:

1 = 0

(0 )
(0 )

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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:

3.2. DIAGRAMA DE FLUJO CON LA DERIVADA:

Inicio
f(x), f(x),
X0, E

X1 = X0 - f(X0)/f(X0)

|X1-X0| >E

10

X0 = X1

X1 = X0 - f(X0) / f(X0)

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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:

11

function pushbutton6_Callback(hObject, eventdata, handles)


close
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

3.4. VENTANA DE DISEO Y APLICACIN:

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 - f(X0)/df

|X1-X0| >E

X0 = X1

12

h = 0,00001

X1 = X0 - f(X0)/df

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

3.6.

2012

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:
13

4.1. TEORA:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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:

+1 =

( )(1 )
(1 ) ( )

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:


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

4.3. CDIGO DE PROGRAMA:

14

CDIGO EN EL BOTN CALCULAR:


| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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)));
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:

15

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

5. MTODO DE LIN:
5.1. TEORA:
Dada la ecuacin () = 0 donde P tiene la forma:
() = 0 + 1 1 + 2 2 + + 1 + ; 0 0 (1)
Sea el factor cuadrtico:
2 + + . (2)
Con lo cual la ecuacin anterior resulta:
() = ( 2 + + )(0 2 + 1 3 + + 3 + ) + +
Donde + es el residuo
Polinomio reducido () = 0 2 + 1 3 + + 3 +
Multiplicando ()
() = ( + + ) + ( + + ) + ( + + ) +
+ ( + + ) + ( + + ) + +

Igualando coeficientes de la misma potencia


0 = 0
1 = 0 + 1
2 = 0 + 1 + 2
3 = 1 + 2 + 3
.
1 = 3 + 2 +
= 2 +

0 =
1 =
2 =
3 =

0
1 0
2 0 1
3 1 2

= 1 2 3
= 2
| Clculo numrico

16

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

En general: = 1 2 ; = 0,1,2,3 . 2
Los residuos estn dados por:
= 1 2 3
= 2
Para que 2 + + sea un factor cuadrtico R y S tienen que ser cero.
= 1 2 3 = 0 =

= 2 = 0 =
2
Se define:

1 3
2

Entonces

Si =

5.2. DIAGRAMA DE FLUJO:


INICIO

LEER
a(i); i=1,2,3...n
p, q, E, n

P>E & Q>E

k=n:1:-1
b(n+1)=0
b(n+2)=0
b(k)=a(k)-p*b(k+1)-q*b(k+2)

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(n+1)=0;
c(n+2)=0;
c(i)=b(i)-p*c(i+1)-q*b(i+2)

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);

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

| Clculo numrico
p=p+P;
q=q+Q;
x1=(-p+sqrt(p^2-4*q))/2;

17

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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

18

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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;
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

19

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

SISTEMA DE ECUACIN LINEAL


6. MTODO DE GAUSS - JORDAN
6.1. TEORA:
Sea un sistema de ecuaciones lineales de la forma:
11 1 + 12 2 + 13 3 + + 1 = 1
21 1 + 22 2 + 23 3 + + 2 = 2
31 1 + 32 2 + 33 3 + + 3 = 3

{1 1 + 2 2 + 3 3 + + =
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:
11
21
31

(11

12
22
32

12

13
23
33

13

1
1
1
2
2
2
3 = 3
3

1 ) ( ) ( )

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.
11
21
31

(1

12
22
32

13
23
33

1 1
2 2
3 |3 Matriz aumentada
|

| Clculo numrico

20

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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.
1
0
0

0
(

0
1
0

0
0
1

01
0 2
|
0| 3 Matriz transformada

1 )

Y las races del sistema de ecuaciones son:


1 = 1 ; 2 = 2 ; 3 = 3 ; ; =
El proceso, requiere de

3
2

+ 2 2 multiplicaciones y

3
2

2 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)

21
j = 0, n, 1

akj = akj pivote*aij

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

6.3.

2012

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));

22

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

cadena=[cadena;cad];
end
set(handles.edit2,'string',cadena);
CDIGO EN EL BOTN SALIR:
function varargout = pushbutton3_Callback(h, eventdata, handles,
varargin)
close

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:
23

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

11 1 + 12 2 + 13 3 + + 1 = 1
21 1 + 22 2 + 23 3 + + 2 = 2
31 1 + 32 2 + 33 3 + + 3 = 3

{1 1 + 2 2 + 3 3 + + =
Que matricialmente se puede escribir como A X=B, supongamos que
0, = 1,2,3 . Despejamos los X
1 = (1 12 2 13 3 1 )11
2 = (2 21 1 23 3 2 )22
3 = (3 31 1 32 2 + 3 )33

El proceso se inicia dando un valor inicial para los puntos ; = 1,2,3 .


se podra usar, por ejemplo la solucin trivial 1 = 2 = 3 = = = 0 si
este fuera el caso se tendra que:
1 = 1 11
2 = (2 21 (1 11 ))22
3 = (3 31 (1 11 ) 32 (2 21 (1 11 ))22 )33
..
Los 1, 2, . . . , son los nuevos valores inciales que sern utilizados en una
segunda iteracin.
La convergencia puede definirse mediante
= |

1
| 100 <

Dnde:
: Error relativo porcentual dela raz
: Iteracin actual
1: 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.

| Clculo numrico

24

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

| | > | | >
=1

=1

7.2. 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

25

S = S + aij * Xj

vi = (bi-S) / aii

Xi = vi

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

7.3.

2012

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

26

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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)
close(gauusseidel)

7.4.

VENTANA DE DISEO Y APLICACIN:

27

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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:
x x0 x1 x2 xn
y y0 y1 y2

El objetivo es encontrar una funcin continua lo ms sencilla posible tal que:


() =

(0 )

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

28

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)))

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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)
| Clculo numrico

29

Universidad Nacional "JORGE BASADRE GROHMANN"

8.4.

2012

VENTANA DE DISEO Y APLICACIN:

INTERPOLACIN POLINMICA
9. POLINOMIO DE LAGRANGE:
9.1. TEORA:
Si 0 , 1 , 2 , , son + 1 puntos distintos y () es una funcion cuyos
valores estan dados en esos puntos entonces existe un nico polinomio P de
grado a lo mas de grado n con la propiedad que ( ) = ( ) para cada k=0,
1,2,n.
Este polinomio est dado por:

() = ( ) , ()
=0

Dnde:

, () =
=0

Para un polinomio lineal la aproximacin es:


() = (0 )1,0 () + (1 )1,1 ()
Dnde:
| Clculo numrico

30

Universidad Nacional "JORGE BASADRE GROHMANN"

1,0 () =

1
;
0 1

() = (

1
0
) (0 ) + (
) (1 )
0 1
1 0

1,1 () =

2012

0
1 0

Entonces:

Para un polinomio de segundo grado est dado por:


() = (0 )2,0 () + (1 )2,1 () + (2 )2,2 ()
Dnde:

1
2
1,0 () = (
)(
)
0 1 0 2
0
2
2,1 () = (
)(
)
1 0 1 2
0
1
2,2 () = (
)(
)
2 0 2 1

Entonces el polinomio para segundo grado es:


1
2
0
2
0
1
() = (
)(
) (0 ) + (
)(
) (1 ) + (
)(
) (2 )
0 1 0 2
1 0 1 2
2 0 2 1

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

31

i~=k

N = N(x-x(i))
D = D(x(k)-x(i))

| Clculo numrico
L = N/D

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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:

32

function pushbutton3_Callback(hObject, eventdata, handles)


f=inline(get(handles.edit2,'string'));
ezplot(f),grid on
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

CDIGO EN EL BOTN SALIR:


function varargout = pushbutton3_Callback(h, eventdata, handles,
varargin)
close(polinomiolagrange)

9.4.

VENTANA DE DISEO Y APLICACIN:

33

AJUSTES POLINOMIALES
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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:
= 0 + 1 + 2 2 + + , <
Tal que:
2

S(a 0 , a 1 ,....., a m ) p m x k y k a 0 a 1 x k a 2 x 2k ,....., a m x mk y k


k 0

k 0

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, = 0, 1, 2, , sean cero.
Resultan entonces las siguientes m+1 ecuaciones lineales en las incgnitas
0, 1, . . , m:

n
S
2 a 0 a 1 x k a 2 x 2k ..... a m x mk y k 0
a 0 k 0
n
S
2 a 0 a 1 x k a 2 x 2k ..... a m x mk y k x k 0
a 1 k 0
n
S
2 a 0 a 1 x k a 2 x 2k ..... a m x mk y k x 2k 0
a 2 k 0

..........
n
S
2 a 0 a 1 x k a 2 x 2k ..... a m x mk y k x kj 0
a j k 0

............
n
S
2 a 0 a 1 x k a 2 x 2k ..... a m x mk y k x mk 0
| Clculo numrico
a m k 0

34

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

Si en las ecuaciones anteriores cancelamos el 2, desarrollamos los parntesis


y usamos que
n

a
k 0

n 1a 0

Obtenemos:
n
n
n

n 1a 0 x k a 1 x 2k a 2 ..... x mk a m

k 0
k 0
k 0

n
n
n

n m 1

2
3
x k a 0 x k a 1 x k a 2 ..... x k a m
k 0
k 0
k 0

kn0
n
n
n

x 2 a x 3 a x 4 a ..... x m 2 a
k 1
k m
k
0
k
2

k 0
k 0

k 0
k 0
.

.
n
n
n
n
x j a x 1 j a x 2 j a ..... x m j a

k
0
k
1
k
2
k
m
k 0
k 0
k 0
k 0

n
n 1 m
n 2 m
n mm

m
x
a

x
a

x
a

.....

x k a m

k
0
k
1
k
2

k 0

k 0

k 0

k 0

yk
k 0

x k yk
k 0

n 2
x k yk
k 0

...

...

n j
x k yk
k 0

:::
n

x mk y k
k 0

Este es un SEL de m+1 ecuaciones lineales en las m+1 incgnitas a 0, a1, ..,
am, que se llama Sistema de Ecuaciones Normales. Este sistema de ecuaciones
normales se puede escribir en forma simplificada como sigue:
m

i 0

k 0

k 0

a i x ik j x kj y k

con j 0,1,....,.m

Estas ecuaciones se pueden reproducir a partir de:

p m x k a 0 a 1 x k a 2 x 2k ,....., a m x mk y k
35

Multiplicando a ambos lados por , = 0, 1, , ,

a 0 x kj a 1 x k x kj a 2 x 2k x kj ,....., a m x mk x kj y k x kj
a 0 x kj a 1 x 1k j a 2 x 2k j ,....., a m x mk j x kj y k

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

Sumando sobre k
n

k 0

k 0

k 0

k 0

k 0

a 0 x kj a 1 x 1k j a 2 x 2k j ..... a m x mk j x kj y k

10.2.

con j 0,1,2,....., m

DIAGRAMA DE FLUJO:

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

36

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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;
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:

37

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

CAPITULO - III
INTEGRACIN NUMRICA
11. REGLA DEL TRAPECIO:
11.1.

TEORA:
Este mtodo resulta de sustituir la funcin = () por un polinomio de
primer grado () = 0 + 1 en [, ] = [0 , 1 ] al polinomio () se le
puede representar mediante un polinomio () se le puede representar
mediante un polinomio de Lagrange, es decir:

1
1 (
( 0 )
1 )
() = () = [
(0 ) +
(1 )]
(1 0 )

0
0 (0 1 )

Resolviendo:

() = [(0 ) (1 )], = 1 0
2

Generalizando:

() + () + () + + () =

()

Aplicando la regla del trapecio a c/u de las integrales se tiene:

| Clculo numrico

38

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

() = lim ( )

11.2.

=1

DIAGRAMA DE FLUJO:

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

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'));
| Clculo numrico

39

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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:
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)
40

11.4. VENTANA DE DISEO Y APLICACION:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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:

() () () = 0 + 1 + 2 2

En el intervalo [, ] = [0 , 2 ] al polinomio () se le puede representar por


un polinomio de LaGrange de segundo orden
Es decir:

() [(0 )2,0 () + (1 )2,1 () + (2 )2,2 ()]

1
1
2
0
2
0
1
() [(
)(
) (0 ) + (
)(
) (1 ) + (
)(
) (2 )]

0
1
0
2
1
0
1
2
2
0
2 1

Resolviendo la integral se obtiene:

2 0
() [(0 ) + 4(1 ) + (2 )], =
3
2

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:


| Clculo numrico

41

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

() [(0 ) + 4(1 ) + 2(2 ) + 4(3 ) + 2(4 ) + + 2(2 ) + 4(1 ) + ( )]


3

Dnde:
0
=
=
; 2

= 0 + ; = 1,2,3

12.2.

DIAGRAMA DE FLUJO:
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

42
FIN

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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;
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
| Clculo numrico

43

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

ezplot(f,[min(x):0.2:max(x)])
CDIGO EN EL BOTN SALIR:
function varargout = pushbutton3_Callback(h, eventdata, handles, varargin)
close(sinpson1/3)

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:

() () () = 0 + 1 + 2 2 + 3 3

44
En el intervalo [, ] = [0 , 2 ] al polinomio () se le puede representar
por un polinomio de LaGrange de tercer orden.
Es decir:
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

=3

[(0 )3,0 () + (1 )3,1 () + (2 )3,2 () + (3 )3,3 ()]

()

=0

Resolviendo la integral se obtiene:

()


[( ) + ( ) + ( ) + ( )], =

13.2. DIAGRAMA DE FLUJO:


Inicio
S=0

Leer
f(X), a, b, n

h = (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-1) + 3f(Xi-1)+f(Xi)

Escribir
S

FIN

13.3. CDIGO DE PROGRAMA:

CDIGO EN EL BOTN CALCULAR:

45

function varargout = pushbutton3_Callback(h, eventdata, handles, varargin)


| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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
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)]);

46

CDIGO EN EL BOTN SALIR:


| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

function pushbutton5_Callback(hObject, eventdata, handles)


close

13.4.

VENTANA DE DISEO Y APLICACIN:

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

| Clculo numrico

47

Universidad Nacional "JORGE BASADRE GROHMANN"

2 ()

2012

(, )

1 ()

Utilizando la regla de Simpson 1/3


1 =
Por lo tanto:

2 =

2 ()

2 0
;
2

2 () 1 ()
2

(, ) = () =

1 ()

1
[(0 ) + 4(1 ) + (2 )]
3

Dnde:
() =

2
[(, 1 ()) + 4(, 1 () + 2 ()) + (, 2 ())]
3

14.2. DIAGRAMA DE FLUJO


INICIO
LEER
f(x,y), g1(x), g2(x), a, b
h=(b-a)/2
x0=a
s=0

48

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

| Clculo numrico
I=(h/3)*(w(1)+4*w(2)+w(3))

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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);
| Clculo numrico

49

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

grid on
CDIGO EN EL BOTN SALIR:
function pushbutton5_Callback(hObject, eventdata, handles)
close

14.4. VENTANA DE DISEO Y APLICACIN:

CAPITULO - IV
ECUACIONES DIFERENCIALES ORDINARIAS
15. METODO DE EULER:
15.1.

50

TEORA:
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

Este mtodo consiste en dividir el intervalo [, ] en n subintervalos de


()
longitud 'h'; = ,de manera que se obtiene los n+ 1 puntos 0 , 1 ,
2 , . ., = donde = 0 + ; = 1,2,3 la condicin inicial
(0 ) = 0 representada por el punto 0 = (0 , 0 ) por donde pasa la curva
solucin, donde :

|
= (0 , 0 )
(0 ,0 )

FORMULA DE EULER
+1 = + ( , )

, = 1,2,3

Es decir, se genera una sucesin de aproximacin:


1 = 0 + (0 , 0 )
2 = 1 + (1 , 1 )
3 = 2 + (2 , 2 )
51

= 1 + (1 , 1 )
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

15.2.

2012

DIAGRAMA DE FLUJO:

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

15.3.

CDIGO DE PROGRAMA:
52

CDIGO EN EL BOTN CALCULAR:


function varargout = pushbutton1_Callback(h, eventdata, handles,
varargin)
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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);
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)
53

f1=get(handles.edit1,'string');
f=inline(f1,'x','y');
ezmesh(f);
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

grid on

CDIGO EN EL BOTN SALIR:


function pushbutton7_Callback(hObject, eventdata, handles)
close

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 (0 ) = 0 entonces por el segundo teorema fundamenta del
clculo se tiene:
| Clculo numrico

54

Universidad Nacional "JORGE BASADRE GROHMANN"

+1

2012

= ( +1 ) ( )

Para aplicar la regla de Simpson de 1/3 a [ , +1 ] se le dividi en dos


intervalos es decir:
Entonces
+1

/2

[ ( ) + 4 ( + ) + (+1 )]
3
2

Al trmino 4 ( + 2) se le expresa como: 2 ( + 2) + 2 ( + 2)

para aproximar la pendiente de ( + 2) en el punto promedio ( + 2)

(+1 ) = ( ) + [ ( ) + 2 ( + ) + 2 ( + ) + (+1 )]
6
2
2
Pero
= ( , )
Por EULER se tiene que: (+1 ) = ( ) + ( , )
Hacemos cambios de variables:
Hagamos 1 = ( ) entonces 1 = ( , )

Hagamos 2 = ( + 2) entonces 2 = ( + 2 , ( + 2)) por

euler : ( + ) = ( ) + ( , ) entonces
2
2

2 = ( + , + 1 )
2
2

Hagamos 3 = ( + 2) entonces 3 = ( + 2 , ( + 2))

por

euler ( + 2) = ( ) + 2 ( , ) entonces:

3 = ( + , + 2 )
2
2

(
Hagamos 4 = + 1) entonces 4 = ( + 2 , ( + 2)) por euler

( + 1) = ( ) + ( + 2) entonces:
4 = ( + 1, 0 + 3 )
Por lo tanto:

Dnde:

( + 1) = + [1 + 22 + 33 + 4 ]
6
=

+1
; .

| Clculo numrico

55

Universidad Nacional "JORGE BASADRE GROHMANN"

16.2.

2012

DIAGRAMA DE FLUJO:

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

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'));

56

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2012

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;
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:

57

| Clculo numrico

You might also like