Professional Documents
Culture Documents
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.
FIAG-ESIC
INDICE:
PAGINA
UNIDAD I
INTERPOLACION Y REGRESION
INTERPOLACION-POLINOMIO DE LAGRANGE16
REGRESION LINEAL19
REGRESION POLINOMIAL.22
UNIDAD II
SISTEMA DE ECUACIONES
METODO DE GAUSS-JORDAN.27
METODO DE GAUSS-SEIDEL30
INTEGRACIONES NUMERICAS
METODO DEL TRAPECIO..37
METODO DE SIMPSON 1/340
METODO DE SIMPSON 3/845
2
FIAG-ESIC
INTEGRACION DOBLE47
UNIDAD III
UNIDAD I:
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
FIAG-ESIC
x n=( a+b)/2
b=x n
f (a)f ( x n)>0
a=x n
Entonces
para
determinar
en
que
x n Es la Raz
x n+1=( a+b)/2
( 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
DIAGRAMA DE FLUJO:
FIAG-ESIC
FIAG-ESIC
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);
FIAG-ESIC
end
else
set(handles.edit5,'string','No existe la raiz en el intervalo');
end
FIAG-ESIC
g(x)=f ( x)+ x .
x0 y
x=g( x ) , definida en la
calculamos
una
nueva
aproximacin
x 1=g ( x 0) .
{ x 0 , x 1, , x n }
y=x
x1
ms prximo a
la solucin final.
FIAG-ESIC
g ' (x)
es menor en valor
y=x .
g ( x ) =x+ f (x )
CONVERGENCIA:
El mtodo de aproximaciones sucesivas converge si
g ' (x) 1
Co
Convergencia Montona
Divergencia Montona
FIAG-ESIC
DIAGRAMA DE FLUJO:
10
FIAG-ESIC
11
FIAG-ESIC
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:
functionvarargout = pushbutton1_Callback(h, eventdata, handles, varargin)
funcionf=get(handles.edit1,'string');
f=inline(funcionf);
figure(1);
ezplot(f),grid on
12
FIAG-ESIC
x 1=x 0
x0
y obtiene una
f ( x0 )
f ' (x 0 )
f ( xi)
hace que
13
FIAG-ESIC
y=f ( x)
14
FIAG-ESIC
15
FIAG-ESIC
CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
functionvarargout = 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:
functionvarargout = 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
16
FIAG-ESIC
17
FIAG-ESIC
18
FIAG-ESIC
4. MTODO DE LA SECANTE:
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
f (x)
x
f ( x i1 ) f ( i)
f ( xi )(x i1 xi )
x i+1=x i
19
FIAG-ESIC
CDIGO DE PROGRAMA:
20
FIAG-ESIC
21
FIAG-ESIC
INTERPOLACIN Y REGRESION
5. INTERPOLACION-POLINOMIO DE LAGRANGE:
22
FIAG-ESIC
x0 , x1 , x2 , , xn
son
n+1
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 propiedad que
f ( x k ) =P( x k )
para
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
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
L1,0 ( x )=
23
xx 1
x 0x 1
)(
xx 2
x 0 x2
)
FIAG-ESIC
L2,1 ( x )=
L2,2 ( x )=
(
(
xx 0
x1 x0
xx 0
x2 x0
)(
)(
xx 2
x 1x 2
xx 1
x 2x 1
)
)
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
24
FIAG-ESIC
25
FIAG-ESIC
CDIGO DE PROGRAMA:
26
FIAG-ESIC
27
FIAG-ESIC
6. REGRESIN LINEAL:
TEORIA:
Supongamos que hemos medido un conjunto de pares de datos (xi, yi) en una
experiencia, por ejemplo, la posicin de un mvil en ciertos instantes de tiempo.
Queremos obtener una funcin y=f(x) que se ajuste lo mejor posible a los valores
experimentales. Se pueden ensayar muchas funciones, rectas, polinomios,
funciones potenciales o logartmicas.
Una vez establecido la funcin a ajustar se determina sus parmetros, en el caso
de un polinomio, sern los coeficientes del polinomio de modo que los datos
experimentales se desven lo menos posible de la frmula emprica.
La funcin ms sencilla es la funcin lineal y=ax+b que hemos tratado en la pgina
anterior. El procedimiento de ajustar los datos experimentales a una lnea recta se
denomina regresin lineal.
POLINOMIO APROXIMADOR
Queremos aproximar un polinomio de grado n, a un conjunto de m pares de datos
(xi,yi) de modo que n y m.
Sea el polinomio
P(x)=a0+a1x+a2x2+...anxn
Se calcula la cantidad:
Para obtener los valores de los coeficientes del polinomio aproximador se tienen
que determinar los valores de los coeficientes a0, a1, a2, ...an de forma que la
cantidad S tome un valor mnimo.
Hagamos las derivadas parciales de S respecto de a0, a1, a2, ...an iguales a cero
28
FIAG-ESIC
(1)
Obtenemos un sistema de n+1 ecuaciones con n+1 incgnitas, a0, a1, a2, ...an
DIAGRAMA DE FLUJO:
29
FIAG-ESIC
CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
x=str2num(get(handles.edit1,'string'));
y=str2num(get(handles.edit2,'string'));
Sx=0;
Sy=0;
Sx2=0;
Sxy=0;
n=length(x);
for i=1:n
Sx=Sx+x(i); Sy=Sy+y(i); Sx2=Sx2+(x(i))^2; Sxy=Sxy+(x(i))*(y(i));
end
a=(n*Sxy-Sx*Sy)/(n*Sx2-(Sx)^2);
b=(Sy-a(1)*Sx)/n;
d=sprintf('%5.3f x + %5.3f',a,b);
set(handles.edit3,'string',d)
CDIGO EN EL BOTN GRAFICAR:
x=str2num(get(handles.edit1,'string'));
y=str2num(get(handles.edit2,'string'));
Sx=0;
Sy=0;
Sx2=0;
Sxy=0;
n=length(x);
for i=1:n
Sx=Sx+x(i); Sy=Sy+y(i); Sx2=Sx2+(x(i))^2; Sxy=Sxy+(x(i))*(y(i));
end
a=(n*Sxy-Sx*Sy)/(n*Sx2-(Sx)^2);
b=(Sy-a(1)*Sx)/n;
Y=a*x+b;
plot(x,Y),hold on
plot(x,y,'r*'),grid on
legend('f(x)','ptos iniciales')
pan on
30
FIAG-ESIC
7. REGRESIN POLINOMIAL :
TEORA:
Supongamos que se conocen los datos
,y
con
,x
, .., x n
,y
x
,
,y
x
, ..
encontrar un polinomio:
31
FIAG-ESIC
k 0
Sea mnima.
( x)
a
S
Volviendo a la funcin
,a
, .., a
de
a
S
,a
, .., a
con
respecto
a ,
j
,a
, .., a
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
a m k 0
32
FIAG-ESIC
a
Obtenemos:
n 1 a 0
k 0
n 1 a 0 x k a 1 x 2k a 2 ..... x mk a m
n
x
k 0
n
x
k 0
k 0
n
a0
k 0
n
a0
k 0
a1
x
k 0
n
x
k 0
.
.
x kj a 0
k 0
4
k
a 2 .....
a 2 .....
k 0
n
k 0
n
x
k 0
m 1
k
k 0
n
k 0
n
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
am
x 2k j a 2 .....
k 0
yk
2
k
yk
...
:::
am
m2
k
x 1k j a 1
k 0
x mk a 0
k 0
k 0
n
a1
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 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
p m x k a 0 a 1 x k a 2 x 2k ,....., a m x mk y k
Multiplicando a ambos lados por
x ij , j=0, 1, , m,
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
33
con j 0,1,2,....., m
FIAG-ESIC
DIAGRAMA DE FLUJO:
34
FIAG-ESIC
CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
function pushbutton1_Callback(hObject, eventdata, handles)
x=str2num(get(handles.edit1,'string'));
y=str2num(get(handles.edit2,'string'));
n=str2double(get(handles.edit3,'string'));
[m p]=size(x);
for i=1:n+1
for j=1:n+1
S=0;
for k=1:m
S=S+(x(k))^(i+j-2);
end
M(i,j)=S;
end
end
for i=1:n+1
SB=0;
for k=1:m
SB=SB+((x(k))^(i-1))*y(k);
end
B(i,1)=SB;
end
M=M;
B=B;
A=inv(M)*B;
A=A';
set(handles.edit4,'string',num2str(A));
CDIGO EN EL BOTN GRAFICAR:
function pushbutton2_Callback(hObject, eventdata, handles)
x=str2num(get(handles.edit1,'string'));
y=str2num(get(handles.edit2,'string'));
n=str2double(get(handles.edit3,'string'));
temp=str2num(get(handles.edit4,'string'));
[m p]=size(x);
for i=1:n+1
Px(i)=temp(n-i+2);
end
Px=Px
dom=min(x)-1.5:.2:max(x)+1.5;
35
FIAG-ESIC
36
FIAG-ESIC
UNIDAD II
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
37
FIAG-ESIC
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
( |)
1
0
0
0
1
0
0
0
1
0b 1
0b 2
0 b 3
1 b n
Matriz transformada
El proceso, requiere de
38
n3 2 n
+n
2
2
multiplicaciones y
n3 n
2 2
sumas.
FIAG-ESIC
DIAGRAMA DE
FLUJO:
39
FIAG-ESIC
CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
functionvarargout = 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';
40
FIAG-ESIC
41
FIAG-ESIC
42
FIAG-ESIC
x i ; i=1,2,3 . n se
si este
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
43
FIAG-ESIC
Ex =
i
x i j xi j1
xi j
100<T
Dnde:
Ex
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
DIAGRAMA DE FLUJO:
44
FIAG-ESIC
45
FIAG-ESIC
46
FIAG-ESIC
47
FIAG-ESIC
48
FIAG-ESIC
49
FIAG-ESIC
x3=%7.3f\n',i,a,b,c);
50
FIAG-ESIC
INTEGRACIN NUMRICA
11. REGLA DEL TRAPECIO:
TEORA:
51
FIAG-ESIC
y=f ( x)
P ( x )=a0 +a1 x
primer grado
en
por un polinomio de
[ a , b ] =[ x 0 , x 1 ] al polinomio P( x) se
P( x)
se le puede
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
f ( x ) dx=lim f (x n) x k
a
n k=1
DIAGRAMA DE FLUJO:
52
FIAG-ESIC
53
FIAG-ESIC
CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
functionvarargout = 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:
functionvarargout = 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)])
54
FIAG-ESIC
55
FIAG-ESIC
En el intervalo
[ a , b ] =[ x 0 , x2 ] al polinomio
P (x )
se le puede representar
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
f ( x ) dx h3 [ f ( x 0 ) +4 f ( x 1 ) +f ( x 2 ) ] , donde h=
a
x 2x 0
2
56
FIAG-ESIC
x4
x6
xn
x2
x4
x n2
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:
h=
ba x nx 0
=
; donde n es multiplo de 2
n
n
x i=x 0+ ih ; i=1,2,3 n
DIAGRAMA DE FLUJO:
57
FIAG-ESIC
58
FIAG-ESIC
CDIGO DE PROGRAMA:
59
FIAG-ESIC
60
FIAG-ESIC
y=f (x)
b
61
FIAG-ESIC
En el intervalo
b =x 3
a =x 0
x 2x 0
3
DIAGRAMA DE FLUJO:
62
FIAG-ESIC
CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
functionvarargout = 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
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:
functionvarargout = 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
63
FIAG-ESIC
64
FIAG-ESIC
14.
INTEGRALES MLTIPLES
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 )
donde h 1=
x 2x 0
g ( x )g1 (x )
; h 2= 2
2
2
Por lo tanto:
65
FIAG-ESIC
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
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
66
FIAG-ESIC
CDIGO DE PROGRAMA:
CDIGO EN EL BOTN CALCULAR:
function pushbutton1_Callback(hObject, eventdata, handles)
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'));
n=str2double(get(handles.edit7,'string'));
h=(b-a)/n;
x0=a;
for i=1:n+1
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=0;
d=1;
for i=1:n/2
I=I+(h/3)*(w(d)+4*w(d+1)+w(d+2));
d=d+2;
end
set(handles.edit6,'string',I);
CDIGO EN EL BOTN GRAFICAR:
function pushbutton2_Callback(hObject, eventdata, handles)
f=get(handles.edit1,'string');
f1=inline(f,'x','y');
ezmesh(f1);
grid on
CDIGO EN EL BOTN LIMPIAR:
function pushbutton3_Callback(hObject, eventdata, handles)
set(handles.edit1,'string','');
set(handles.edit2,'string','');
set(handles.edit3,'string','');
set(handles.edit4,'string','');
67
FIAG-ESIC
68
FIAG-ESIC
UNIDAD III
'h';
h=
x 0 , x 1 , x 2 , .. , x n =x f
y ( x0 ) = y 0
( ba )
n
donde
[a ,b ]
en n subintervalos de
x i=x 0+ ih ; i=1,2,3 n
P0=( x 0 , y 0 )
la condicin
inicial
dy
dx
69
( x 0 , y0 )
=f ( x 0 , y 0 )
FIAG-ESIC
FORMULADE 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 )
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)
DIAGRAMA DE FLUJO:
70
FIAG-ESIC
71
FIAG-ESIC
CDIGO DE PROGRAMA:
CDIGO EN EL BOTN OK:
function pushbutton1_Callback(h, eventdata, handles, varargin)
f1=get(handles.edit1,'string');
x0=str2double(get(handles.edit2,'string'));
y0=str2double(get(handles.edit6,'string'));
n=str2double(get(handles.edit3,'string'));
b=str2double(get(handles.edit4,'string'));
f=inline(f1,'x','y');
h=(b-x0)/n;
m=sprintf('x(0)=%5.3f y(0)=%5.3f\n',x0,y0);
cad=[m];
for i=1:n
y0=y0+h*f(x0,y0);
x0=x0+h;
cadena=sprintf('x(%d)=%6.3f y(%d)=%6.3f\n',i,x0,i,y0);
cad=[cad,cadena];
end
set(handles.edit5,'string',y0);
set(handles.edit17,'string',cad);
CDIGO EN EL BOTN LIMPIAR:
functionvarargout = pushbutton3_Callback(h, eventdata, handles, varargin)
set(handles.edit1,'string','');
set(handles.edit2,'string','');
set(handles.edit3,'string','');
set(handles.edit4,'string','');
set(handles.edit5,'string','');
set(handles.edit6,'string','');
set(handles.edit7,'string','');
CDIGO EN EL BOTN GRAFICAR:
functionvarargout = pushbutton2_Callback(h, eventdata, handles, varargin)
72
FIAG-ESIC
73
FIAG-ESIC
y ( x 0)= y 0
entonces por el
y'=
dy
=f ( x , y )
dx
con condiciones
clculo se tiene:
'
y dx = y ( x n+1) y (x n)
x n+1
xn
74
FIAG-ESIC
[ 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
4 y' x n +
h
2
se le expresa como:
y ' x n+
y ( xn +1 )= y ( x n ) +
h
2
2 y' x n +
h
h
+2 y ' x n+
2
2
) (
en el punto promedio
h '
h
h
y ( x n ) +2 y' x n + +2 y ' x n+ + y ' ( x n+1 )
6
2
2
) (
( x + h2 )
n
Pero
y ' =f ( x n , y n )
y ( xn +1 )= y ( x n ) +h f ( x n , y n )
k 1= y ' ( x n ) entonces
Hagamos
k 1=f ( x n , y n )
x
h
k 2= y ' x n +
2
Hagamos
y xn +
entonces
por
euler
h
h
= y ( x n ) + f ( x n , y n ) entonces
2
2
h
h
k 2=f x n + , y n + k 1
2
2
75
h
y ( n+ )
2
h
xn + ,
2
k 2=f
)
FIAG-ESIC
k 3 = y ' xn +
Hagamos
y xn +
h
2
entonces
h
y ( n+ )
2
h
xn + ,
2
k 3=f
por
euler
por
euler
h
h
= y ( x n ) + y ' ( x n , y n ) entonces:
2
2
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 +
entonces
h
2
h
y ( n+ )
2
h
xn + ,
2
k 4=f
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:
h=
76
x n+1 xn
; mes el numero de intervalos .
m
FIAG-ESIC
DIAGRAMA DE FLUJO:
77
FIAG-ESIC
CDIGO DE PROGRAMA:
CDIGO EN EL BOTN OK:
function varargout = pushbutton1_Callback(h, eventdata, handles, varargin)
f=inline(get(handles.edit1,'string'),'x','y');
n=str2double(get(handles.edit2,'string'));
x0=str2double(get(handles.edit3,'string'));
y0=str2double(get(handles.edit4,'string'));
xn=str2double(get(handles.edit6,'string'));
h=(xn-x0)/n;
cad=[];
cad2=[];
for i=1:n
K1=f(x0,y0);
K2=f(x0+h/2,y0+K1*h/2);
K3=f(x0+h/2,y0+K2*h/2);
K4=f(x0+h,y0+K3*h);
y0=y0+h*(K1+2*K2+2*K3+K4)/6;
yn=sprintf('%d: %5.4f\n',i,y0);
cad=[cad,yn];
x0=x0+h;
xn=sprintf('%d: %5.4f\n',i,x0);
78
FIAG-ESIC
79
FIAG-ESIC
17.
80
Y1(x0)=d1
FIAG-ESIC
Y2(x0)=d2
Y3(x0)=d3
CODIGO DE PROGRAMA:
CODIGO PARA EL BOTON CALCULAR:
function pushbutton1_Callback(hObject, eventdata, handles)
f1x=get(handles.edit1,'string');
f2x=get(handles.edit2,'string');
f3x=get(handles.edit3,'string');
x0=str2double(get(handles.edit4,'string'));
xn=str2double(get(handles.edit5,'string'));
y1=str2double(get(handles.edit6,'string'));
y2=str2double(get(handles.edit7,'string'));
y3=str2double(get(handles.edit8,'string'));
n=str2double(get(handles.edit9,'string'));
f1=inline(f1x,'x','y1','y2','y3');
f2=inline(f2x,'x','y1','y2','y3');
f3=inline(f3x,'x','y1','y2','y3');
h=(xn-x0)/n;
cad1='';
for i=1:n
81
FIAG-ESIC
82
FIAG-ESIC
83
FIAG-ESIC
Y (n1 ) ( x 0 )=dn
Y (xf)=?
La estrategia es convertir la ecuacin diferencial en un sistema de ecuaciones
diferenciales lineales de primer orden.
Sea:
u1=Y
un= Y
(n1)
u2=Y
84
FIAG-ESIC
..
u3(x0)=d3un(x0)=d(n-1)
CODIGO DE PROGRAMA:
CODIGO PARA EL BOTON CALCULAR:
function pushbutton1_Callback(hObject, eventdata, handles)
f1=inline('u2','x','u1','u2');
f2=inline(get(handles.edit1,'string'),'x','u1','u2');
a=str2double(get(handles.edit2,'string'));
b=str2double(get(handles.edit3,'string'));
u1=str2double(get(handles.edit4,'string'));
u2=str2double(get(handles.edit5,'string'));
n=str2double(get(handles.edit6,'string'));
h=(b-a)/n;
x=a;
cad1='';
85
FIAG-ESIC
86
FIAG-ESIC
87
FIAG-ESIC
x [a, b]
Y(a)=
Y(b)=
Dada una discretizacion de la regin:
X(i)=a+i*h i=0,1,2..N h=(b-a)/N
Y se aproximan las derivadas mediante (operadores en diferencias). Por ejemplo
utilizando que:
88
FIAG-ESIC
2*h*h*qi-4=bi
2+pi*h=ci
89
FIAG-ESIC
90
FIAG-ESIC
91
FIAG-ESIC
92
FIAG-ESIC
93
FIAG-ESIC
94
FIAG-ESIC