trabajo de calculo numerico
DESCRIPTION
TRANSCRIPT
2012
INTRODUCCIÓNTanto la ciencia y la tecnología nos describen los fenómenos reales mediante modelos matemáticos. El estudio de estos modelos permite un conocimiento más profundo del fenómeno, así como de su evolución futura.Desafortunadamente, no siempre es posible aplicar métodos analíticos clásicos por diferentes razones: La solución formal es tan complicada que hace imposible cualquier interpretación posterior; simplemente no existen métodos analíticos capaces de proporcionar soluciones al problema; no se adecuan al modelo concreto; o su aplicación resulta excesivamente compleja.Para este tipos de casos son útiles las técnicas numéricas, que mediante una labor de cálculo más o menos intensa, conducen a soluciones aproximadas que son siempre numéricos. La importante del cálculo radica en que implica la mayoría de estos métodos hacen que su uso esté íntimamente ligado al empleo de computadores, que mediante la programación nos permite la solución de problemas matemáticos. Para la realización de este trabajo se utilizó el programa MATLAB.
|
2012
CAPITULO I: CÁLCULO DE RAÍCES DE ECUACIONES
1. MÉTODO DE LA BISECCIÓN:1.1.TEORÍA:
En matemáticas, el método de bisección es un algoritmo de búsqueda de raíces que trabaja dividiendo el intervalo a la mitad y seleccionando el subintervalo que tiene la raíz.PROCEDIMIENTO:
Elija valores Iniciales para “a” y “b” de forma tal que lea función cambie de signo sobre el intervalo. Esto se puede verificar asegurándose de que : f (a)∗f (b)<0
La primera aproximación a la raíz se determina con la fórmula: xn=(a+b) /2
Realizar las siguientes evaluaciones para determinar en que subintervalo se encuentra la raíz: f (a)∗f (xn) < 0 Entonces b=xn
f (a)∗f (x n)>0 Entonces a=xn
f (a)∗f (x n)=0 Entonces xn Es la Raíz Calcule la nueva aproximación:
xn+1=(a+b) /2
Evaluar la aproximación relativa: |
2012
¿(xn+1−xn)/ xn+1∨¿ E
No. (Falso) Repetir el paso 3, 4 y 5 Sí. (Verdadero) Entonces xn+1Es la Raíz
1.2.DIAGRAMA DE FLUJO:
|
2012
1.3.CÓDIGO DE PROGRAMA: CÓDIGO 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); endelse set(handles.edit5,'string','No existe la raiz en el intervalo');end
CÓDIGO EN EL BOTÓN GRAFICAR:function varargout = pushbutton2_Callback(h, eventdata, handles, varargin) f=get(handles.edit1,'string');f=inline(f);ezplot(f), grid on
CÓDIGO EN EL BOTÓN SALIR: |
2012
function pushbutton6_Callback(hObject, eventdata, handles)close
1.4.VENTANA DE DISEÑO Y APLICACIÓN:
2. MÉTODO DEL PUNTO FIJO:2.1. TEORÍA:
Dada la ecuación f (x)=0, el método de las aproximaciones sucesivas reemplaza esta ecuación por una equivalente, x=g(x ), definida en la forma g(x )=f (x)+x . Para encontrar la solución, partimos de un valor inicial x 0 y calculamos una nueva aproximación x1=g(x 0) . Reemplazamos el nuevo valor obtenido y repetimos el proceso. Esto da lugar a una sucesión de valores, {x0 , x1 ,…, xn }que si converge, tendrá como límite la |
2012
solución del problema. En la figura se representa la interpretación geométrica del método. Partimos de un punto inicial x0 y calculamos y=g (x0). La intersección de esta solución con la recta y=x nos dará un nuevo valor x1 más próximo a la solución final. Sin embargo, el método puede divergir fácilmente. Es fácil comprobar que el método sólo 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 condición, que a priori puede considerarse una severa restricción del método, puede obviarse fácilmente. Para ello basta elegir la función g(x ) del siguiente modo:
g ( x )=x+∝ f (x)
De forma que tomando un valor de ∝ adecuado, siempre podemos hacer que g ( x ) cumpla la condición de la derivada. CONVERGENCIA:El método de aproximaciones sucesivas converge si ¿ g '(x )∨¿1
|
2012
Co Convergencia Monótona Divergencia Monótona
0<g ' ( x )<1g ' (x)>1
2.2.DIAGRAMA DE FLUJO:
2.3. CÓDIGO DE PROGRAMA: |
2012
CÓDIGO EN EL BOTÓN 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
CÓDIGO EN EL BOTÓN GRAFICAR:function varargout = pushbutton1_Callback(h, eventdata, handles, varargin)funcionf=get(handles.edit1,'string');f=inline(funcionf);figure(1);ezplot(f),grid on
CÓDIGO EN EL BOTÓN SALIR:function pushbutton6_Callback(hObject, eventdata, handles)close
2.4.VENTANA DE DISEÑO Y APLICACIÓN:
|
2012
3. MÉTODO DE NEWTON RAPHSON: |
2012
3.1.TEORÍA:Este método parte de una aproximación inicial x0 y obtiene una aproximación mejor,x1, dada por la fórmula:
x1=x0−f (x0)f ' (x0)
Este método está definido por el denominador f ’ (xi) hace que geométricamente se base en una aproximación a una recta tangente a la curva y=f (x ) trazada en el punto correspondiente a la aproximación presente, esto puede observarse en la figura:
3.2.DIAGRAMA DE FLUJO CON LA DERIVADA:
|
2012
3.3.CÓDIGO DE PROGRAMA: CÓDIGO EN EL BOTÓN 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);
CÓDIGO EN EL BOTÓN GRAFICAR: |
2012
function varargout = pushbutton2_Callback(h, eventdata, handles, varargin) f=get(handles.edit1,'string');f=inline(f);ezplot(f), grid on
CÓDIGO EN EL BOTÓN SALIR:function pushbutton6_Callback(hObject, eventdata, handles)close
3.4.VENTANA DE DISEÑO Y APLICACIÓN:
3.5. SIN INGRESAR LA DERIVADA: f ’(x) DIAGRAMA DE FLUJO:
|
2012
3.6. CÓDIGO DE PROGRAMA: CÓDIGO EN EL BOTÓN 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);
CÓDIGO EN EL BOTÓN GRAFICAR:function varargout = pushbutton2_Callback(h, eventdata, handles, varargin)
|
2012
f=get(handles.edit1,'string');f=inline(f);ezplot(f), grid on
4. MÉTODO DE LA SECANTE:4.1.TEORÍA:
El principal inconveniente del método de Newton estriba en que requiere conocer el valor de la primera derivada de la función en el punto. Sin embargo, la forma funcional de f (x) dificulta en ocasiones el cálculo de la derivada. En estos casos es más útil emplear el método de la secante. El método de la secante parte de dos puntos (y no sólo uno como el método de Newton) y estima la tangente (es decir, la pendiente de la recta) por una aproximación de acuerdo con la expresión:
x i+1=x i−f (x i)(x i−1−x i)
f (x i−1 )−f (x¿¿ i)¿
En general, el método de la secante presenta las mismas ventajas y limitaciones que el método de Newton-Raphson explicado anteriormente. 4.2.DIAGRAMA DE FLUJO:
|
2012
4.3.CÓDIGO DE PROGRAMA: CÓDIGO EN EL BOTÓN CALCULAR:
function varargout = pushbutton3_Callback(h, eventdata, handles, varargin) f=inline(get(handles.edit1,'string'));x0=str2double(get(handles.edit2,'string'));x1=str2double(get(handles.edit3,'string'));E=str2double(get(handles.edit4,'string')); while abs(x1-x0)>E x2=x1-(((x1-x0)*f(x1))/(f(x1)-f(x0))); x0=x1; x1=x2;endset(handles.edit5,'string',x2)
CÓDIGO EN EL BOTÓN GRAFICAR:function varargout = pushbutton4_Callback(h, eventdata, handles, varargin) f=get(handles.edit1,'string');f=inline(f);ezplot(f), grid on
CÓDIGO EN EL BOTÓN SALIR:function pushbutton3_Callback(hObject, eventdata, handles)close(secante)
4.4.VENTANA DE DISEÑO y APLICACION: |
2012
5. MÉTODO DE LIN:5.1. TEORÍA:
Dada la ecuación P(x )=0 donde P tiene la forma:
P ( x )=a0 xn+a1 x
n−1+a2 xn−2+…+an−1 x+an; a0≠0… (1)
Sea el factor cuadrático:x2+ px+q….(2)
Con lo cual la ecuación anterior resulta:
P ( x )=(x2+ px+q ) (b0 xn−2+b1 x
n−3+…+bn−3 x+bn )+Rx+S
Donde Rx+S es el residuo
Polinomio reducido Q ( x )=b0 xn−2+b1 x
n−3+…+bn−3 x+bn
Multiplicando P(x )
|
2012
P ( x )=(b0 xn+ pb0 x
n−1+qb0 xn−2 )+(b1 x
n−1+ pb1 xn−2+q b1 x
n−3 )+(b2 xn−2+ pb2 x
n−3+qb2 xn−4 )+…+(bn−3 x
3+ pbn−3 x2+qbn−3 x )+(bn−2 x
2+ pbn−2 x+qbn−2 )+Rx+S
Igualando coeficientes de la misma potencia
a0=b0b0=a0
a1=p b0+b1b1=a1−pb0
a2=qb0+ pb1+b2b2=a2−q b0−pb1
a3=qb1+ pb2+b3b3=a3−q b1−pb2
…. …….an−1=qbn−3+ pbn−2+R R=an−1−qbn−2−pbn−3
an=qbn−2+S S=an−qbn−2
En general: bk=ak−pbk−1−qbk−2 ;k=0,1,2,3….n−2
Los residuos están dados por:
R=an−1−pbn−2−qbn−3
S=an−qbn−2
Para que x2+ px+q sea un factor cuadrático R y S tienen que ser cero.
R=an−1−pbn−2−qbn−3=0entonces p=an−1−qbn−3
bn−2
S=an−qbn−2=0entoncesq=anbn−2
Se define:
Si ∆ p=Rbn−2
y ∆q= Sbn−2
5.2. DIAGRAMA DE FLUJO:
|
Entonces
2012
5.3. CÓDIGO DE PROGRAMA:
CÓDIGO EN EL BOTÓN 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);
|
2012
endfor i=n:-1:1 c(n+1)=0; c(n+2)=0; c(i)=b(i)-p*c(i+1)-q*b(i+2);endP=(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);endp=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);
CÓDIGO EN EL BOTÓN CALCULAR:function pushbutton2_Callback(hObject, eventdata, handles)close
5.4. VENTANA DE DISEÑO Y APLICACIÓN:
|
2012
CAPITULO IISISTEMA DE ECUACIÓN LINEAL
6. MÉTODO DE GAUSS - JORDAN6.1.TEORÍA:
Sea un sistema de ecuaciones lineales de la forma:
{a11 x1+a12 x2+a13 x3+…+a1n xn=b1
a21 x1+a22 x2+a23 x3+…+a2n xn=b2
a31 x1+a32 x2+a33 x3+…+a3n xn=b3
……an1 x1+an2 x2+an3 x3+…+ann xn=bn
Se trata de un sistema de n ecuaciones con n incógnitas, x1, x2, ..., xn. Los elementos aij y bi son números reales fijados. El sistema de ecuaciones se puede escribir, empleando una muy útil representación matricial, como:
|
2012
(a11 a12 a13 ⋯ a1n
a21 a22 a23 ⋯ a2n
a31 a32 a33 ⋯ a3n
⋮ ⋮ ⋮ ⋱ ⋮a11 a12 a13 ⋯ a1n
)(x1
x2
x3
⋮xn
)=(b1
b2
b3
⋮bn
)Es decir A X=B
Donde A es la matriz de coeficientes, X es el vector incógnitas y B es el vector términos 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 a12 a13 ⋯ a1n
a21 a22 a23 ⋯ a2n
a31 a32 a33 ⋯ a3n
⋮ ⋮ ⋮ ⋱ ⋮an1 an2 an3 ⋯ ann
|b1
b2
b3
⋮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 están en la posición del vector de términos independientes B, será la solución del sistema.
(1 0 0 ⋯ 00 1 0 ⋯ 00 0 1 ⋯ 0⋮ ⋮ ⋮ ⋱ ⋮0 0 0 ⋯ 1
|b¿
1
b¿2
b¿3
⋮b
¿n
) Matriz transformada
Y las raíces del sistema de ecuaciones son:x1=b
¿1; x2=b
¿2 ; x3=b
¿3;…; xn=b
¿n
El proceso, requiere de n3
2+n2−n
2 multiplicaciones y n3
2−n
2 sumas.
|
2012
6.2.DIAGRAMA DE FLUJO:
6.3. CÓDIGO DE PROGRAMA: CÓDIGO EN EL BOTÓN CALCULAR:
|
2012
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 endend for i=1:m x(i)=A(i,n);endx=x'; t=1:m; t=t';cadena='';for t=1:m cad=sprintf('x%d=%6.2f',t,x(t)); cadena=[cadena;cad];endset(handles.edit2,'string',cadena);
CÓDIGO EN EL BOTÓN SALIR:function varargout = pushbutton3_Callback(h, eventdata, handles, varargin)close
6.4. VENTANA DE DISEÑO Y APLICACIÓN:
|
2012
7. MÉTODO DE GAUSS SEIDEL7.1.TEORÍA:
Método iterativo que su utiliza para resolver sistema de ecuaciones de la forma:
{a11 x1+a12 x2+a13 x3+…+a1n xn=b1
a21 x1+a22 x2+a23 x3+…+a2n xn=b2
a31 x1+a32 x2+a33 x3+…+a3n xn=b3
……an1 x1+an2 x2+an3 x3+…+ann xn=bn
Que matricialmente se puede escribir como A X=B, supongamos que a ii≠0 ,i=1,2,3….n Despejamos los X
x1=(b1−a12 x2−a13 x3−…−a1n xn )/a11
x2=(b2−a21 x1−a23 x3−…−a2n xn )/ a22
x3=(b3−a31 x1−a32 x2−…+a3n xn )/a33……El proceso se inicia dando un valor inicial para los puntos x i; i=1,2,3….n se podría usar, por ejemplo la solución trivial x1=x2=x3=…=xn=0 si este fuera el caso se tendría que:x1=b1/ a11
|
2012
x2=(b2−a21 (b1/a11)) /a22
x3=(b3−a31 (b1/a11)−a32 (b2−a21 (b1/a11)) /a22)/a33…..Los x1 , x2 , ... , x nson los nuevos valores iníciales que serán utilizados en una segunda iteración.La convergencia puede definirse mediante
E x i=|x i j−x i
j−1
xij |100<T
Dónde:Ex i: Error relativo porcentual dela x i raízj: Iteración actualj−1: Iteración anteriorT : Tolerancia prefijadaRE ARREGLO DE ECUACIONESEl 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 demás elementos de la misma fila o columna .Es decir se asegura la convergencia sí.
|aii|>∑i=1j ≠i
n
aij ó|a ii|>∑i=1j ≠i
n
a ji
7.2.DIAGRAMA DE FLUJO:
|
2012
7.3. CÓDIGO DE PROGRAMA: CÓDIGO EN EL BOTÓN CALCULAR:
|
2012
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);endfor t=1:n cad2=sprintf('x%d=%10.8f ',t,x(t)); cad1=[cad1,cad2];endcad2=sprintf('\n',t);cad1=[cad1,cad2];end set(handles.edit5,'string',cad1);
CÓDIGO EN EL BOTÓN SALIR:function varargout = pushbutton3_Callback(h, eventdata, handles, varargin)close(gauusseidel)
7.4. VENTANA DE DISEÑO Y APLICACIÓN: |
2012
INTERPOLACIÓN8. INTERPOLACIÓN LINEAL:
8.1.TEORÍA: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 función para cualquier x perteneciente a dicho intervalo. Supongamos que disponemos de las siguientes parejas de datos:
x x0 x1 x2 … xn
|
2012
y y0 y1 y2 … yn
El objetivo es encontrar una función continua lo más sencilla posible tal que:( x i )= y i(0≤ i≤n)
Se dice entonces que la función f (x) definida por la ecuación es una función de interpolación de los datos representados en la tabla. Existen muchas formas de definir las funciones de interpolación, lo que da origen a un gran número de métodos (polinomios de interpolación de Newton, interpolación de Lagrange, interpolación de Hermite, etc). Sin embargo, nos centraremos exclusivamente en dos funciones de interpolación: Los polinomios de interpolación de Lagrange. Las funciones de interpolación splines. Estas funciones son especialmente importantes debido a su idoneidad en los cálculos realizados con ordenador.
8.2.DIAGRAMA DE FLUJO:
|
2012
8.3.CÓDIGO DE PROGRAMA: CÓDIGO EN EL BOTÓN 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; endendset(handles.edit4,'string',y);
CÓDIGO EN EL BOTÓN SALIR:function varargout = pushbutton3_Callback(h, eventdata, handles, varargin)close(interpolacionlineal)
8.4. VENTANA DE DISEÑO Y APLICACIÓN:
|
2012
INTERPOLACIÓN POLINÓMICA9. POLINOMIO DE LAGRANGE:
9.1.TEORÍA:Si 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 (xk )=P(xk ) para cada k=0, 1,2,…n.Este polinomio está dado por:
P ( x )=∑k=0
n
f ( xk) Ln , k (x) polinomio de lagrange
Dónde:Ln , k ( x )=∏
i=0i ≠k
n x−x ixk−xi
Para un polinomio lineal la aproximación es:P ( x )=f (x0 ) L1,0 ( x )+ f (x1) L1,1(x )
Dónde:L1,0 ( x )=
x−x1
x0−x1
; L1,1(x )=x−x0
x1−x0Entonces:P ( x )=( x−x1
x0−x1) f (x0 )+( x−x0
x1−x0) f (x1 )
Para un polinomio de segundo grado está dado por:P ( x )=f (x0 ) L2,0 ( x )+ f (x1) L2,1 ( x )+ f (x2 )L2,2(x )
|
2012
Dónde:L1,0 ( x )=( x−x1
x0−x1)( x−x2
x0−x2)
L2,1 ( x )=( x−x0
x1−x0)( x−x2
x1−x2)
L2,2 ( x )=( x−x0
x2−x0)( x−x1
x2−x1)
Entonces el polinomio para segundo grado es:P ( x )=( x−x1
x0−x1)( x−x2
x0−x2) f (x0 )+( x−x0
x1−x0)( x−x2
x1−x2) f (x1)+( x−x0
x2−x0)( x−x1
x2−x1) f (x2 )
Donde x es el valor a interpolar.9.2. DIAGRAMA DE FLUJO:
|
2012
9.3.CÓDIGO DE PROGRAMA: CÓDIGO EN EL BOTÓN 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)));endset(handles.edit4,'string',s);
CÓDIGO EN EL BOTÓN GRAFICAR:function pushbutton3_Callback(hObject, eventdata, handles)f=inline(get(handles.edit2,'string'));ezplot(f),grid on
CÓDIGO EN EL BOTÓN SALIR:function varargout = pushbutton3_Callback(h, eventdata, handles, varargin)close(polinomiolagrange)
|
2012
9.4. VENTANA DE DISEÑO Y APLICACIÓN:
AJUSTES POLINOMIALES10. REGRESIÓN POLINOMIAL :
10.1. TEORÍA: |
2012
Supongamos que se conocen los datos ¿o, yo¿ ,¿1, y1¿ ,… ..¿n, yn¿ con x0, x1,… .. , x n números reales distintos, y se desea encontrar un polinomio:Pm=a0+a1 x+a2 x
2+…+amxm , conm<n
Tal que:
2n
0kk
mkm
2k2k10
2n
0kkkmm10 yxa,.....,xaxaayxp)a,.....,a,S(a
Sea mínima.El grado m del polinomio pm(x ) se puede escoger previamente con base en algún resultado teórico, alguna expectativa o por la aplicación 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 mínimos cuadrados para la tabla de datos.Volviendo a la función S¿0, a1,… .. , am¿ , una condición necesaria para la existencia de un mínimo relativo de esta función es que las derivadas parciales de S¿0, a1,… .. , am¿con respecto a aj, j=0 ,1,2 ,…,m sean cero.Resultan entonces las siguientes m+1 ecuaciones lineales en las incógnitas a0, a1,… .. , am:
|
0xyxa.....xaxaa2a
S
............
0xyxa.....xaxaa2a
S
..........
0xyxa.....xaxaa2a
S
0xyxa.....xaxaa2a
S
0yxa.....xaxaa2a
S
mkk
mkm
2k2k10
n
0km
jkk
mkm
2k2k10
n
0kj
2kk
mkm
2k2k10
n
0k2
kkmkm
2k2k10
n
0k1
kmkm
2k2k10
n
0k0
2012
Si en las ecuaciones anteriores cancelamos el 2, desarrollamos los paréntesis y usamos que
Obtenemos:
Este es un SEL de m+1 ecuaciones lineales en las m+1 incógnitas a0, a1, ….., am, que se llama Sistema de Ecuaciones Normales. Este sistema de ecuaciones normales se puede escribir en forma simplificada como sigue:
Estas ecuaciones se pueden reproducir a partir de:Multiplicando a ambos lados por x ji , j=0 ,1 ,…,m,
|
0
n
0k0 a1na
n
0kk
mkm
n
0k
mmk2
n
0k
m2k1
n
0k
m1k0
n
0k
mk
n
0kk
jkm
n
0k
jmk2
n
0k
j2k1
n
0k
j1k0
n
0k
jk
n
0kk
2km
n
0k
2mk2
n
0k
4k1
n
0k
3k0
n
0k
2k
n
0kkkm
n
0k
1mk2
n
0k
3k1
n
0k
2k0
n
0kk
n
0kkm
n
0k
mk2
n
0k
2k1
n
0kk0
yxax.....axaxax
:::
yxax.....axaxax
.......
.
yxax.....axaxax
yxax.....axaxax
yax.....axaxa1n
m0,1,....,.jconyxxan
0kk
jk
n
0k
jik
m
0ii
kmkm
2k2k10km yxa,.....,xaxaaxp
kjk
jmkm
j2k2
j1k1
jk0
jkk
jk
mkm
jk
2k2
jkk1
jk0
yxxa,.....,xaxaxa
xyxxa,.....,xxaxxaxa
2012
Sumando sobre k
10.2. DIAGRAMA DE FLUJO:
10.3. CÓDIGO DE PROGRAMA: |
m.,0,1,2,....jconyxxa.....xaxaxam
0kk
jk
m
0k
jmkm
n
0k
j2k2
n
0k
j1k1
n
0k
jk0
2012
CÓDIGO EN EL BOTÓN 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);enda=((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);
CÓDIGO EN EL BOTÓN 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 DISEÑO Y APLICACION:
|
2012
CAPITULO - IIIINTEGRACIÓN NUMÉRICA11. REGLA DEL TRAPECIO:
11.1. TEORÍA:Este método resulta de sustituir la función y=f (x ) por un polinomio de primer grado P ( x )=a0+a1 x en[a ,b ]= [x0 , x1 ] al polinomio P(x ) se le puede representar mediante un polinomio P(x ) se le puede representar mediante un polinomio de Lagrange, es decir:
∫a
b
f ( x )dx=¿∫x0
x1
P ( x )dx=¿∫x0
x1 [ (x−x1 )(x0−x1 )
f (x0 )+( x−x0 )(x1−x0 )
f (x1) ]dx¿¿
Resolviendo:∫a
b
f ( x )dx=¿ h2
[ f (x0)−f (x1)] , dondeh=x1−x0¿
Generalizando:∫a
b
f ( x )dx+¿∫x0
x1
f ( x )dx+∫x1
x2
f ( x )dx+…+∫x0
x1
f ( x )dx=¿∫xn−1
xn
f (x )dx ¿¿
|
2012
Aplicando la regla del trapecio a c/u de las integrales se tiene:∫a
b
f ( x )dx= limn→∞
∑k=1
n
f (xn)∆ xk 11.2. DIAGRAMA DE FLUJO:
11.3.CÓDIGO DE PROGRAMA: CÓDIGO EN EL BOTÓN ACEPTAR:
function varargout = pushbutton4_Callback(h, eventdata, handles, varargin)
|
2012
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));endI=s*(h/2);set(handles.edit5,'string',I);
CÓDIGO EN EL BOTÓN 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));endx=[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));endhold onezplot(f,[min(x):0.2:max(x)])plot(x,y,'og')plot(x,y,'g')
CÓDIGO EN EL BOTÓN SALIR:function varargout = pushbutton3_Callback(h, eventdata, handles, varargin)close(trapecio)
|
2012
11.4.VENTANA DE DISEÑO Y APLICACION:
12. REGLA DE SIMPSON 1/3:12.1. TEORÍA:
La regla de Simpson de 1/3 resulta cuando se sustituye la función y=f(x) por un polinomio de segundo grado es decir:
∫a
b
f ( x )dx ≈∫a
b
P ( x )dx donde P ( x )=a0+a1 x+a2 x2
En el intervalo [a ,b ]=[ x0, x2] al polinomio P ( x ) se le puede representar por un polinomio de LaGrange de segundo ordenEs decir:
∫a
b
f ( x )dx ≈∫a
b
[f (x0 ) L2,0 ( x )+ f (x1) L2,1 ( x )+ f (x2 )L2,2(x )]dx
∫a
b
f ( x )dx ≈∫x0
x1 [( x−x1
x0−x1)( x−x2
x0−x2) f (x0 )+( x−x0
x1−x0)( x−x2
x1−x2) f (x1 )+( x−x0
x2−x0)( x−x1
x2−x1) f ( x2 )]dx
Resolviendo la integral se obtiene:
∫a
b
f ( x )dx ≈ h3 [ f (x0 )+4 f ( x1 )+ f (x2) ] , dondeh=
x2−x0
2
GENERALIZANDO PARA ''n'' INTERVALOS
Los intervalos se toman de dos en dos:
|
2012
∫a
b
f ( x )dx=¿∫x0
x2
f ( x )dx+∫x2
x4
f (x )dx+∫x4
x6
f ( x )dx+…+∫xn−2
xn
f ( x )dx ¿
Aplicando la regla de Simpson de 1/3 para cada integral de tiene:
∫a
b
f ( x )dx ≈ h3 [ f (x0 )+4 f ( x1 )+2 f (x2 )+4 f (x3 )+2 f (x4 )+…+2 f (xn−2 )+4 f (xn−1 )+ f (xn ) ]
Dónde:
h=b−an
=xn−x0
n;dondenes multiplode2
x i=x0+ih; i=1,2,3…n
12.2. DIAGRAMA DE FLUJO:
|
2012
12.3.CÓDIGO DE PROGRAMA: CÓDIGO EN EL BOTÓN 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;endif 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)) endI=(h/3)*s set(handles.edit5,'string',I);end
CÓDIGO EN EL BOTÓN 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));endx=[x,b,a,a];
|
2012
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))]);endhold onezplot(f,[min(x):0.2:max(x)])
CÓDIGO EN EL BOTÓN SALIR:function varargout = pushbutton3_Callback(h, eventdata, handles, varargin)close(sinpson1/3)
12.4. VENTANA DE DISEÑO Y APLICACIÓN:
13. REGLA DE SIMPSON DE 3/8:13.1. TEORÍA:
|
2012
La regla de Simpson de 3/8 resulta cuando se sustituye la función y=f (x ) por un polinomio de tercer grado es decir:
∫a
b
f ( x )dx ≈∫a
b
P ( x )dx donde P ( x )=a0+a1 x+a2 x2+a3 x
3
En el intervalo [a ,b ]=[ x0 , x2] al polinomio P ( x ) se le puede representar por un polinomio de LaGrange de tercer orden.Es decir:
∫a
b
f ( x )dx ≈ ∫a=x0
b=x3
[ f (x0 )L3,0 ( x )+f (x1 ) L3,1 ( x )+ f (x2 ) L3,2 (x )+ f ( x3 ) L3,3(x )]dx
Resolviendo la integral se obtiene:
∫a
b
f (x )dx ≈ 3h8 [ f (x0 )+3 f (x1 )+3 f (x2)+ f (x3 ) ] , dondeh=
x2−x0
313.2. DIAGRAMA DE FLUJO:
|
2012
13.3.CÓDIGO DE PROGRAMA: CÓDIGO EN EL BOTÓN CALCULAR:
function varargout = pushbutton3_Callback(h, eventdata, handles, varargin)
f=inline(get(handles.edit1,'string'))a=str2double(get(handles.edit2,'string'))b=str2double(get(handles.edit3,'string'))n=str2double(get(handles.edit4,'string'))h=(b-a)/nfor i=1:n+1 x(i)=a+(i-1)*hendif 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
CÓDIGO EN EL BOTÓN 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));endx=[x,b,a,a]
|
2012
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))])endhold onezplot(f,[min(x):0.2:max(x)]);
CÓDIGO EN EL BOTÓN SALIR:function pushbutton5_Callback(hObject, eventdata, handles)close
13.4. VENTANA DE DISEÑO Y APLICACIÓN:
14. INTEGRALES MÚLTIPLES
14.1. TEORÍA:Para el cálculo 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.
|
2012
En esta ocasión usaremos Simpson de 1/3 para el cálculo de una integral doble de la forma:
∫R
.
∫ f ( x , y )dA
Dónde:R={( x , y )/a≤ x≤b ;c ≤ y ≤d }R={( x , y )/a≤ x≤b;c ≤g ( x )≤d }
Para aproximar la solución de la integral
∫a
b
∫g1 ( x )
g2 ( x )
f ( x , y )dy dx
Utilizando la regla de Simpson 1/3
donde h1=x2−x0
2;h2=
g2(x)−g1(x)2
Por lo tanto:
∫a
b
∫g1 ( x )
g2 ( x )
f ( x , y )dy dx=∫x0
x2
w ( x )dx=h1
3 [w (x0 )+4w (x1 )+w (x2 ) ]
Dónde:
w (x )=h2
3[ f (x ,g1 ( x ))+4 f (x ,g1 ( x )+h2(x))+f (x , g2 ( x ))]
14.2. DIAGRAMA DE FLUJO
|
2012
14.3. CÓDIGO DE PROGRAMA:
CÓDIGO EN EL BOTÓN 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;endI=(h/3)*(w(1)+4*w(2)+w(3));set(handles.edit6,'string',I);
|
2012
CÓDIGO EN EL BOTÓN GRAFICAR:function pushbutton3_Callback(hObject, eventdata, handles)% hObject handle to pushbutton3 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)f=get(handles.edit1,'string');f1=inline(f,'x','y');ezmesh(f1);grid on
CÓDIGO EN EL BOTÓN SALIR:function pushbutton5_Callback(hObject, eventdata, handles)close
14.4. VENTANA DE DISEÑO Y APLICACIÓN:
|
2012CAPITULO - IVECUACIONES DIFERENCIALES ORDINARIAS15. METODO DE EULER:
15.1. TEORÍA:Este método consiste en dividir el intervalo [a ,b] en n subintervalos de
longitud 'h'; h=(b−a )n
,de manera que se obtiene los n+ 1 puntos
x0 , x1 , x2 ,.. , xn=x f donde x i=x0+ih; i=1,2,3…n la condición inicial y (x0 )= y0 representada por el punto P0=(x0 , y0) por donde pasa la curva solución, donde :
dydx|(x0 , y0)
=f (x0 , y0 )
FORMULA DE EULER
|
2012
y i+1= y i+h (x i , y i ) ,i=1,2,3…n
Es decir, se genera una sucesión de aproximación:
y1= y0+h f (x0 , y0 )
y2= y1+h f ( x1 , y1 )
y3= y2+h f (x2 , y2 )
…
yn= yn−1+h f (xn−1 , yn−1 )
15.2. DIAGRAMA DE FLUJO:
|
2012
15.3. CÓDIGO DE PROGRAMA: CÓDIGO EN EL BOTÓN 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;endset(handles.edit6,'string',y0);
CÓDIGO EN EL BOTÓN 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));
|
2012
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];endset(handles.edit7,'string',cad1);
CÓDIGO EN EL BOTÓN GRAFICAR:function varargout = pushbutton2_Callback(h, eventdata, handles, varargin) f1=get(handles.edit1,'string');f=inline(f1,'x','y');ezmesh(f);grid on
CÓDIGO EN EL BOTÓN SALIR:function pushbutton7_Callback(hObject, eventdata, handles)close
15.4. VENTANA DE DISEÑO Y APLICACIÓN:
|
2012
16. METODO RUNGE – KUTTA DE CUARTO ORDEN :16.1. TEORÍA:
El método de Runge-Kutta es un método genérico de resolución numérica de ecuaciones diferenciales. Este conjunto de métodos fue desarrollado alrededor del año 1900 por los matemáticos C. Runge y M. W. Kutta.
Este método puede ser usado para resolver un número grande de ecuaciones diferenciales.
Dada la ecuación diferencial ordinaria y'=dydx
=f ( x , y ) con condiciones
iniciales y (x0)= y0 entonces por el segundo teorema fundamenta del cálculo se tiene:
∫xn
xn +1
y ' dx= y (¿ xn+1)− y (xn)¿
Para aplicar la regla de Simpson de 1/3 a [ xn , xn+1 ] se le dividió en dos intervalos es decir:Entonces
∫xn
xn +1
y ' dx=¿ h/23 [ y' (xn )+4 y '(xn+ h2 )+ y ' (xn+1 )]¿
Al término 4 y'( xn+ h2 ) se le expresa como: 2 y
'( xn+ h2 )+2 y ' (xn+ h2 )para aproximar la pendiente de y
' (xn+ h2 )en el punto promedio (xn+ h2 )y (xn+1 )= y (xn )+ h
6 [ y ' (xn )+2 y ' (xn+h2 )+2 y '(xn+ h2 )+ y ' (xn+1 )]Pero
y '=f ( xn , yn )
Por EULER se tiene que:y (xn+1 )= y (xn )+hf (xn , yn )Hacemos cambios de variables:
Hagamos k 1= y ' (xn ) entonces k 1=f (xn , y n)
|
2012
Hagamos k 2= y '( xn+ h2 ) entonces k 2=f ¿ por euler :
y (xn+ h2 )= y (xn )+ h2f (xn , yn ) entonces
k 2=f ( xn+ h2 , yn+ h2 k1) Hagamos k 3= y ' (xn+ h2 ) entonces k 3=f ¿ por euler
y (xn+ h2 )= y (xn )+ h2y ' (xn , y n) entonces:
k 3=f ( xn+ h2 , yn+ h2 k2) Hagamos k 4= y ' (xn+1 ) entonces k 4=f ¿ por euler
y (xn+1 )= y (xn )+h y ' (xn+ h2 ) entonces:
k 4=f (xn+1 , y0+hk3 )Por lo tanto:
y (xn+1 )= yn+h6
[k1+2k2+3k3+k 4 ]Dónde:
h=xn+1−xn
m;mesel numero de intervalos .
16.2. DIAGRAMA DE FLUJO:
|
2012
16.3. CÓDIGO DE PROGRAMA: CÓDIGO EN EL BOTÓN 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;endset (handles.edit6,'string',y1);
CÓDIGO EN EL BOTÓN GRAFICAR:function pushbutton6_Callback(hObject, eventdata, handles)
|
2012
f1=get(handles.edit1,'string');f=inline(f1,'x','y');ezmesh(f);grid on
CÓDIGO EN EL BOTÓN SALIR:function varargout = pushbutton2_Callback(h, eventdata, handles, varargin)close(kutta1)
16.4. VENTANA DE DISEÑO Y APLICACIÓN:
|