Sunteți pe pagina 1din 77

Universidad Nacional "JORGE BASADRE GROHMANN"

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"

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 :

f (a)f (b)<0

La primera aproximacin a la raz se determina con la


frmula:

x n=( a+b)/2

Realizar las siguientes evaluaciones para determinar en


que subintervalo se encuentra la raz:
f (a)f (x n)

< 0 Entonces

f (a)f (x n)>0
f (a)f (x n)=0

Entonces

Entonces

xn

b=x n
a=x n
Es la Raz

Calcule la nueva aproximacin:

x n+1=( a+b)/2
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

Evaluar la aproximacin relativa:

( x n +1x n )/x n +1 E
No. (Falso) Repetir el paso 3, 4 y 5
S. (Verdadero) Entonces

x n+1

Es la Raz

1.2. DIAGRAMA DE FLUJO:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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

Universidad Nacional "JORGE BASADRE GROHMANN"

6
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
handles, varargin)

pushbutton2_Callback(h,

eventdata,

f=get(handles.edit1,'string');
f=inline(f);
ezplot(f), grid on
CDIGO EN EL BOTN SALIR:
function pushbutton6_Callback(hObject, eventdata, handles)
close

1.4. VENTANA DE DISEO Y APLICACIN:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2. MTODO DEL PUNTO FIJO:


2.1. TEORA:
Dada la ecuacin

f (x)=0 , el mtodo de las aproximaciones

sucesivas reemplaza esta ecuacin por una equivalente,


x=g(x ) , definida en la forma g( x)=f ( x)+ x . Para encontrar
x0

la solucin, partimos de un valor inicial


nueva

aproximacin

x 1=g (x 0).

y calculamos una

Reemplazamos

el

nuevo

valor obtenido y repetimos el proceso. Esto da lugar a una


x ,x x
sucesin de valores, { 0 1, , n } que si converge, tendr como
lmite

la

solucin

del

problema.

En la figura se representa la interpretacin geomtrica del


mtodo.
Partimos
de
un
punto
inicial
x0
y
y=g(
x
0)
calculamos
. La interseccin de esta solucin con la
recta

y=x

nos dar un nuevo valor

x1

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
g ' (x) es menor en valor absoluto que la unidad (que es la
pendiente de la recta definida por

y=x .

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 g( x) del
siguiente modo:
g ( x ) =x+ f (x )

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

6
De forma que tomando un
valor de

podemos hacer que

g (x )

adecuado, siempre

cumpla la condicin de la derivada.

CONVERGENCIA:
El mtodo
g ' ( x) 1

de

aproximaciones

sucesivas

converge

si

Co
Convergencia Montona
Montona

Divergencia

0< g' ( x ) <1 g ' (x )>1

2.2. DIAGRAMA DE FLUJO:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

2.4. VENTANA DE DISEO 6Y APLICACIN:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

3. MTODO DE NEWTON RAPHSON:


3.1. TEORA:
Este mtodo parte de una aproximacin inicial
una aproximacin mejor,
x 1=x 0

x1

x0

y obtiene

, dada por la frmula:

f ( x0 )
f ' (x 0 )

Este mtodo est definido por el denominador

f (xi)

hace que

geomtricamente se base en una aproximacin a una recta


y=f ( x)
tangente a la curva
trazada en el punto
correspondiente a la aproximacin
observarse en la figura:

presente,

esto

puede

3.2. DIAGRAMA DE FLUJO CON LA DERIVADA:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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

Universidad Nacional "JORGE BASADRE GROHMANN"

function pushbutton6_Callback(hObject, eventdata, handles)


close

3.4. VENTANA DE DISEO Y APLICACIN:

3.5. SIN INGRESAR LA DERIVADA: f (x) DIAGRAMA


DE FLUJO:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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

Universidad Nacional "JORGE BASADRE GROHMANN"

6 mtodo de Newton estriba en que


El principal inconveniente del
requiere conocer el valor de la primera derivada de la funcin en
el punto. Sin embargo, la forma funcional de f (x) 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:

x
f ( x i1 ) f ( i)
f ( xi )(x i1 xi )
x i+1=x i

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:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

4.3. CDIGO DE PROGRAMA:


| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

CDIGO EN EL BOTN6CALCULAR:
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:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

5. MTODO DE LIN:
5.1. TEORA:
Dada la ecuacin
n

P ( x )=a0 x + a1 x

n1

P( x)=0

+a2 x

n2

donde P tiene la forma:

++ an1 x + an ; a0 0 (1)

Sea el factor cuadrtico:


2
x + px +q .(2)
Con lo cual la ecuacin anterior resulta:
P ( x )= ( x2 + px +q ) ( b0 xn 2 +b 1 x n3 ++b n3 x +bn ) + Rx+ S
Donde

Rx+ S

es el residuo

Polinomio reducido
Multiplicando

Q ( x )=b0 xn 2 +b 1 x n3 ++b n3 x +bn

P( x)

P ( x )=( b0 x n + p b0 x n1 +q b 0 x n2 ) + ( b1 x n1 + p b1 xn 2 +q b1 x n3 ) + ( b2 x n2 + p b2 x n3+ q b2 x n4 ) ++ ( b n3
Igualando coeficientes de la misma potencia
a0 =b0 b0 =a0
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

a1= p b 0+ b1 b1=a 1 p b0

a2=q b0 + p b1 +b 2 b 2=a2q b0 p b 1
a3 =q b1 + p b2 +b 3 b 3=a3 q b1 p b 2
.
.
an1=q bn3 + p bn2 + R R=an1q bn2 p bn3
an =q b n2 + S S=anq bn2
En general:

bk =ak p bk1q bk2 ; k=0,1,2,3 . n2

Los residuos estn dados por:


R=an1 p bn2q bn3
S=anq bn2
x 2+ px +q

Para que

sea un factor cuadrtico R y S tienen que

ser cero.
R=an1 p bn2q bn3=0 entonces p=

an1q bn3
bn2

S=anq bn2=0 entonces q=

an
bn 2

Se define:
Entonces

Si

p=

R
b n2

y q=

S
b n2

5.2. DIAGRAMA DE FLUJO:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"


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)

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

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

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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

Universidad Nacional "JORGE BASADRE GROHMANN"

6
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;
set(handles.edit5,'string',x1);
set(handles.edit6,'string',x2);

CDIGO EN EL BOTN CALCULAR:

function
handles)
close

pushbutton2_Callback(hObject,

eventdata,

5.4. VENTANA DE DISEO Y APLICACIN:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

CAPITULO II
SISTEMA DE ECUACIN LINEAL
6. MTODO DE GAUSS - JORDAN
6.1. TEORA:
Sea un sistema de ecuaciones lineales de la forma:

a11 x 1 +a12 x 2 +a 13 x 3+ +a1 n x n=b1


a21 x 1 +a22 x2 +a 23 x 3+ +a 2n x n=b 2
a31 x 1 +a32 x 2 +a 33 x 3+ +a3 n x n=b3

an 1 x 1 +an 2 x2 +a n 3 x 3 ++a nn x n=b n


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:

a 11
a21
a31

a 11

a12
a22
a32

a12

a13
a23
a33

a13

Es decir

a1 n
a2 n
a3 n

a1 n

x1

b1

)( ) ( )
x2
b2
x3 = b3

xn
bn

A X=B

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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

a11
a21
a31

a n1

a 12
a 22
a 32

an 2

a13
a23
a33

an3

|)

a 1n b1
a 2 n b2
a 3 n b3

ann bn

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.

( |)
1
0
0

0
1
0

0
0
1

0b1

0b2
0 b 3

1 b n

Matriz transformada

Y las races del sistema de ecuaciones son:


x 1=b 1 ; x 2=b 2 ; x 3=b3 ; ; x n=b n

El proceso, requiere de

n3 2 n
+n
2
2

multiplicaciones y

n3 n

2 2

sumas.

6.2. DIAGRAMA DE FLUJO:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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

Universidad Nacional "JORGE BASADRE GROHMANN"

pivote = A(k,i); 6
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

6.4. VENTANA DE DISEO Y APLICACIN:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

7. MTODO DE GAUSS SEIDEL


7.1. TEORA:
Mtodo iterativo
que su utiliza para resolver sistema de
ecuaciones de la forma:

a11 x 1 +a12 x 2 +a 13 x 3+ +a1 n x n=b1


a21 x 1 +a22 x2 +a 23 x 3+ +a 2n x n=b 2
a31 x 1 +a32 x 2 +a 33 x 3+ +a3 n x n=b3

an 1 x 1 +an 2 x2 +a n 3 x 3 ++a nn x n=b n


Que matricialmente se puede escribir
supongamos que
aii 0, i=1,2,3 . n
Despejamos los X

como

X=B,

x 1=( b1 a12 x 2a13 x 3a1 n x n) /a11


x 2=( b2 a21 x 1a23 x 3a 2n x n ) /a22
x 3=( b 3a31 x 1a32 x 2+ a3 n x n ) /a33

El proceso se inicia dando un valor inicial para los puntos


x i ; i=1,2,3 . n
se podra usar, por ejemplo la solucin trivial
x 1=x 2=x3 ==xn =0

si este fuera el caso se tendra que:

x 1=b1 /a11
x 2=( b 2a21 ( b1 /a11 ) ) /a 22
x 3=( b3a31 ( b 1 /a11 )a32 ( b2a21 ( b 1 /a11 ) ) /a22) /a 33

..
Los

x 1 , x 2 ,... , x n son los nuevos valores inciales que sern

utilizados en una segunda iteracin.


| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

6
La convergencia puede definirse
mediante

Ex =
i

x i xi
xi j

j1

100<T

Dnde:
Ex

: Error relativo porcentual dela

xi

raz

j : Iteracin actual
j1 : Iteracin anterior
T : 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.
n

i=1
ji

i=1
j i

|aii|> aij |aii|> a ji

7.2. DIAGRAMA DE FLUJO:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

7.3. CDIGO DE PROGRAMA:


| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

CDIGO EN EL BOTN6CALCULAR:
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)
close(gauusseidel)

7.4. VENTANA DE DISEO Y APLICACIN:


| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

INTERPOLACIN
8. INTERPOLACIN LINEAL:
8.1. TEORA:

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 x perteneciente a

dicho intervalo.
Supongamos que disponemos de las siguientes parejas de
datos:
x x0 x1 x2 xn

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

y y0 y1 y2

yn

El objetivo es encontrar una funcin continua lo ms sencilla


posible tal que:

( x i )= y i(0 i n)
Se dice entonces que la funcin

f ( x)

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.

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

8.2.

DIAGRAMA DE
FLUJO:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

6
INTERPOLACIN
POLINMICA

9. POLINOMIO DE LAGRANGE:
9.1. TEORA:
Si

x0 , x1 , x2 , , xn

n+1

son

puntos distintos y

f ( x)

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
f ( x k ) =P( x k )
propiedad que
para cada k=0, 1,2,n.
Este polinomio est dado por:
n

P ( x )= f ( x k ) Ln ,k (x ) polinomio de lagrange
k=0

Dnde:
n

Ln ,k ( x )=
i=0
ik

xxi
x k x i

Para un polinomio lineal la aproximacin es:


P ( x )=f ( x 0 ) L1,0 ( x ) +f ( x 1 ) L1,1 (x)
Dnde:
L1,0 ( x )=

xx1
xx 0
; L1,1 (x)=
x 0x 1
x 1x 0

Entonces:

P ( x )=

xx 1
xx 0
f ( x0 ) +
f ( x1 )
x 0x 1
x 1x 0

Para un polinomio de segundo grado est dado por:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

6
P ( x )=f ( x 0 ) L2,0 ( x ) +f ( x 1 ) L2,1 ( x ) +f ( x 2 ) L2,2 ( x)

Dnde:
xx 1 xx 2
L1,0 ( x )=
x 0x 1 x 0 x2
L2,1 ( x )=
L2,2 ( x )=

(
(
(

xx 0
x1 x0
xx 0
x2 x0

)(
)(
)(

xx 2
x 1x 2
xx 1
x 2x 1

)
)
)

Entonces el polinomio para segundo grado es:


P ( x )=

xx 1
x 0x 1

)(

xx 2
xx 0
f ( x0 )+
x 0 x2
x 1x 0

)(

xx 2
xx 0
f ( x1 )+
x 1x 2
x 2x 0

)(

xx 1
f ( x2 )
x2 x1

Donde x es el valor a interpolar.

9.2. DIAGRAMA DE FLUJO:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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

9.4. VENTANA DE DISEO Y APLICACIN:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

6
AJUSTES POLINOMIALES

10.REGRESIN POLINOMIAL :
10.1. TEORA:
Supongamos que se conocen los datos
x
, ..

,y

con

,x

, .., x n

,y

x
,

nmeros

,y

reales

distintos, y se desea encontrar un polinomio:


Pm=a0 +a1 x+ a2 x 2 ++ am xm , con m<n
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.
p

El grado m del polinomio

(x)

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 n funcin

a
S

,a

, .., a

una condicin

S
2 a 0 a 1 x k a 2 x 2k ..... a m x mk y k 0
necesaria
la existencia de un mnimo relativo de esta
a 0para
k 0

S que las derivadas parciales


funcin es
de
2
n

,a

, .., a

2 a 0 a 1 x k a 2 x k ..... a m x y0 k x k1 0

k 0
1
con respecto
a
n

a ,
j

j=0,1, 2, , m

m
S
k

sean cero.

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 las siguientes m+1 ecuaciones lineales en las
Resultanentonces
a
..........
incgnitas

,a

, .., a

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

| Clculo numrico

............

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

Universidad Nacional "JORGE BASADRE GROHMANN"

Si en las ecuaciones anteriores cancelamos el 2, desarrollamos


los parntesis y usamos que
n

k 0

n 1 a 0

Obtenemos:

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

x
k 0
n

x
k 0

a0

k
2
k

k 0
n

k 0
n

a0

k 0

a1

k
3
k

a1

x kj a 0

k 0

x mk a 0

k 0

k 0
n

x
k 0
n

x
k 0

.
.

4
k

a 2 .....

a 2 .....

k 0
n

k 0
n

x
k 0

m 1
k
m2
k

am

am

x 2k j a 2 .....

k 0

x mk j a m

k 0

x 1k m a 1

k 0

x 2k m a 2 .....

k 0

x mk m a m

k 0

k 0
n

k 0
n

k 0

...

x 1k j a 1

k 0

yk

2
k

yk

...

:::

x
k 0
n

x
k 0

j
k

yk

m
k

yk

Este es un SEL de m+1 ecuaciones lineales en las m+1


incgnitas a0, a1, .., am, que se llama Sistema de Ecuaciones
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

6 ecuaciones normales se puede


Normales. Este sistema de
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
i

x j , j=0, 1, , m,

Multiplicando a ambos lados por

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

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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

Universidad Nacional "JORGE BASADRE GROHMANN"

6
yy=a*xx+b;
ezplot(x,y,'or',xx,yy),grid on

10.4. VENTANA DE DISEO Y APLICACION:

CAPITULO - III
INTEGRACIN NUMRICA
11.

REGLA DEL TRAPECIO:

11.1.

TEORA:
Este mtodo resulta de sustituir la funcin
polinomio de primer grado

P ( x )=a0 +a1 x

en

y=f ( x)

por un

[ a , b ] =[ x 0 , x 1 ]

al

polinomio

P( x)

se le puede representar mediante un

polinomio

P( x)

se le puede representar mediante un

polinomio de Lagrange, es decir:


| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

6
x1

P ( x ) dx=
x0

( x x1 )
( xx 0 )
f ( x0 ) +
f ( x1 ) dx
( x 0x 1 )
( x 1x 0 )
x1

f ( x ) dx=
x0

Resolviendo:
f ( x ) dx=

h
[ f (x 0)f (x 1) ] , donde h=x 1x 0
2
b

Generalizando:
x2

x1

xn

f ( x ) dx+ f ( x ) dx ++ f ( x ) dx= f ( x ) dx
x1

x0

x n1

x1

f ( x ) dx+
x0

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


tiene:
b

f ( x ) dx=lim
f (x n) x k
n
a

11.2.

k=1

DIAGRAMA DE FLUJO:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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

Universidad Nacional "JORGE BASADRE GROHMANN"

CDIGO EN EL BOTN SALIR:


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

11.4. VENTANA DE DISEO Y APLICACION:

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

f ( x ) dx P ( x ) dx donde P ( x )=a0 + a1 x +a2 x 2


a

En el intervalo

[ a , b ] =[x 0 , x2 ]

al polinomio

P (x )

se le puede

representar por un polinomio de LaGrange de segundo orden


Es decir:
b

f ( x ) dx [ f ( x 0 ) L2,0 ( x ) +f ( x 1 ) L2,1 ( x ) +f ( x 2 ) L2,2 (x)] dx


a

x1

f ( x ) dx
a

x0

[( )( ) ( )( ) ( )( ) ]
xx 1
x 0x 1

xx 2
xx 0
f ( x0 )+
x 0 x2
x 1x 0

xx 2
xx 0
f ( x1 )+
x 1x 2
x 2x 0

xx 1
f ( x 2 ) dx
x2 x1

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

6
Resolviendo la integral se obtiene:
b

f ( x ) dx h3 [ f ( x 0 ) +4 f ( x 1 ) +f ( x 2 ) ] , donde h=
a

x 2x 0
2

GENERALIZANDO PARA ''n'' INTERVALOS


Los intervalos se toman de dos en dos:
x2

x4

x6

xn

f ( x ) dx= f ( x ) dx+ f ( x ) dx + f ( x ) dx+ + f ( x ) dx


x0

x2

x4

x n2

Aplicando la regla
tiene:

de Simpson de 1/3 para cada integral de

f ( x ) dx h3 [ f ( x 0 ) +4 f ( x 1 ) +2 f ( x 2 )+ 4 f ( x 3 )+ 2 f ( x 4 ) ++ 2 f ( xn2 ) + 4 f ( x n1 ) + f ( xn ) ]
a

Dnde:
ba x nx 0
h=
=
; donde n es multiplo de 2
n
n
x i=x 0+ ih; i=1,2,3 n

12.2.

DIAGRAMA DE FLUJO:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

12.3. CDIGO DE PROGRAMA:


CDIGO EN EL BOTN CALCULAR:
function varargout = pushbutton1_Callback(h,
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

eventdata,

CDIGO EN EL BOTN GRAFICAR:


| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

function varargout = pushbutton2_Callback(h,


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

eventdata,

CDIGO EN EL BOTN SALIR:


function varargout = pushbutton3_Callback(h, eventdata, handles,
varargin)
close(sinpson1/3)

12.4. VENTANA DE DISEO Y APLICACIN:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

13.REGLA DE SIMPSON DE 3/8:


13.1.

TEORA:
La regla de Simpson de 3/8 resulta cuando se sustituye la funcin
y=f (x) por un polinomio de tercer grado es decir:
b

f ( x ) dx P ( x ) dx donde P ( x )=a0 + a1 x +a2 x 2+ a3 x 3


a

En el intervalo

[ a , b ] =[x 0 , x2 ]

P (x )

al polinomio

se le puede

representar por un polinomio de LaGrange de tercer orden.


Es decir:
b

b =x 3

f ( x ) dx [ f ( x 0 ) L3,0 ( x ) + f ( x1 ) L3,1 ( x ) + f ( x 2) L3,2 ( x ) + f ( x3 ) L3,3 (x )] dx


a

a =x 0

Resolviendo la integral se obtiene:


b

f (x) dx 38h [ f ( x 0 ) +3 f ( x 1 ) +3 f ( x 2 ) + f ( x 3 ) ] , donde h=


a

x2 x0
3

13.2. DIAGRAMA DE FLUJO:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

13.3. CDIGO DE PROGRAMA:


CDIGO EN EL BOTN CALCULAR:

function varargout
handles, varargin)

pushbutton3_Callback(h,

eventdata,

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

Universidad Nacional "JORGE BASADRE GROHMANN"

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

14.

VENTANA DE DISEO Y APLICACIN:

INTEGRALES MLTIPLES
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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

f ( x , y ) dA
R

Dnde:
R= { ( x , y ) /a x b ; c y d }
R= { ( x , y ) /a x b ; c g ( x ) d }
Para aproximar la solucin de la integral
b g2 ( x )

f ( x , y ) dy dx
a g1 ( x )

Utilizando la regla de Simpson 1/3


donde h 1=

x 2x 0
g 2( x )g1 (x )
; h 2=
2
2

Por lo tanto:
b g2 ( x )

x2

f ( x , y ) dy dx= w ( x ) dx= 31 [ w ( x 0 ) + 4 w ( x 1 ) + w ( x2 ) ]
a g1 ( x )

x0

Dnde:
w ( x )=

h2
[ f (x , g1 ( x ))+ 4 f (x , g1 ( x ) +h2 (x ))+ f (x , g2 ( x ))]
3

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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

Universidad Nacional "JORGE BASADRE GROHMANN"

ezmesh(f1);
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:
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

15.1.

TEORA:
Este mtodo

consiste en dividir el intervalo

subintervalos de longitud 'h';


obtiene

los

n+

x i=x 0+ ih ; i=1,2,3 n

puntos
la

representada por el punto

h=

( ba )
n

[a ,b ]

,de manera que se

x 0 , x 1 , x 2 , .. , x n =x f

condicin
P0=(x 0 , y 0 )

en n

inicial
por donde

donde
y ( x0 ) = y 0
pasa

la

curva solucin, donde :


dy
dx

( x 0 , y0 )

=f ( x 0 , y 0 )

FORMULA DE EULER
y i+1= yi +h ( x i , y i) , i=1,2,3 n
Es decir, se genera una sucesin de aproximacin:
y 1= y 0 +h f ( x 0 , y 0 )
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

y 2= y 1 +h f ( x 1 , y 1 )

y 3= y 2 +h f ( x 2 , y 2)

y n= y n1 +h f ( x n1 , y n1)

15.2.

DIAGRAMA DE FLUJO:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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);
x0=x0+h;
end
set(handles.edit6,'string',y0);
CDIGO EN EL BOTN ITERACIONES:
function varargout
handles, varargin)

pushbutton6_Callback(h,

eventdata,

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;

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

6
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
handles, varargin)

pushbutton2_Callback(h,

eventdata,

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

15.4.

VENTANA DE DISEO Y APLICACIN:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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.
dy
'
y
=
=f ( x , y )
Dada la ecuacin diferencial ordinaria
con
dx
y (x 0)= y 0

condiciones iniciales

entonces por el

segundo

teorema fundamenta del clculo se tiene:


'
y dx = y ( x n+1) y (x n)
x n+1

xn

Para aplicar la regla de Simpson de 1/3

[ x n , x n+1 ]

se le

dividi en dos intervalos es decir:


Entonces
y ' dx =

h /2 '
h
y ( x n ) + 4 y ' x n+ + y ' ( x n+1 )
3
2

xn+ 1

xn

Al

trmino

2 y' x n +

h
h
+2 y ' x n+
2
2

) (

4 y' x n +

h
2

se

le

expresa

como:

)
| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

para

aproximar

la

pendiente

de

y ' x n+

h
2

en

el

punto

( x + h2 )

promedio

y ( xn +1 )= y ( x n ) +

h '
h
h
y ( x n ) +2 y' x n + +2 y ' x n+ + y ' ( x n+1 )
6
2
2

) (

Pero
y ' =f ( x n , y n )
y ( xn +1 )= y ( x n ) +hf ( x n , y n )

Por EULER se tiene que:

Hacemos cambios de variables:


Hagamos

k 1= y ' ( x n )

entonces

k 1=f ( x n , y n )
x

Hagamos

y xn +

h
k 2= y ' x n +
2

h
y ( n+ )
2
h
xn + ,
2
k 2=f

entonces

h
h
= y ( xn )+ f ( xn , yn )
2
2

por euler :

entonces

h
h
k 2=f x n + , y n + k 1
2
2

)
x

Hagamos

y xn +

k 3 = y ' xn +

h
2

h
h
= y ( xn )+ y' ( xn , yn )
2
2

entonces

h
y ( n+ )
2
h
xn + ,
2
k 3=f

por euler

entonces:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

h
h
k 3 =f x n + , y n + k 2
2
2

x
Hagamos

'

k 4= y ( xn +1 )

y ( xn +1 ) = y ( x n) + h y ' x n +

h
2

entonces

h
y ( n+ )
2
h
xn + ,
2
k 4=f

por euler

entonces:

k 4=f ( xn +1, y 0 +h k 3 )
Por lo tanto:
y ( xn +1 ) = y n +

h
[ k +2 k 2 +3 k 3+ k 4 ]
6 1

Dnde:
x x
h= n+1 n ; mes el numero de intervalos .
m

16.2.

DIAGRAMA DE FLUJO:

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

| Clculo numrico

Universidad Nacional "JORGE BASADRE GROHMANN"

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

Universidad Nacional "JORGE BASADRE GROHMANN"

close(kutta1)

16.4.

VENTANA DE DISEO Y APLICACIN:

| Clculo numrico

S-ar putea să vă placă și