Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Índice
Introducción
El método del disparo
El método de las diferencias finitas
Métodos de colocación y de elementos finitos
Introducción 3/34
En este tema analizamos los problemas que se pueden modelizar mediante una
ecuación diferencial de segundo orden con condiciones en dos puntos dados,
extremos de un intervalo de estudio Œa; b.
Shooting method
Con tal fin se genera una sucesión de problemas de valor inicial que converja al 1
2
dado. 3
izquierdo del intervalo.
Luego se resuelve (se dispara) hacia y.b/ y se obtiene el valor real yb en b.
ChE-401: Computational Methods in Chem. Eng.
F .s/ D 0:
function z=F(s)
a=0; b=1; yb=3;
En Matlab podría escribirse así: ydot = @(t,y) [y(2); 4*y(1)];
[t,y]= ode45(ydot,[a,b],[1,s]); % Solver de Matlab
z = y(end,1)-yb
end
Comprobamos que para s D 1, F . 1/ 1;0512 y que F .0/ 0;7622 7/34
3
y
-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Tiempo
8/34
Si y.t/ es una función con derivadas continuas al menos hasta cuarto orden,
sabemos que
0 y.t C h/ y.t h/ h2 000
y .t / D y ./
2h 6
y que
00 y.t C h/ 2y.t/ C y.t h/ h2 000
y .t / D C y ./:
h2 12
for approximations wi to the correct values yi , as shown in Figure 7.6. The boundary
conditions are substituted in the system of equations where they are needed. 9/34
1 w1
w2
ya y1
y2 wn–1
wn
yn–1
yn yb
t
t0 t1 t 2 ... tn–1 tn tn+1
Figure 7.6 The Finite Difference Method for BVPs. Approximations wi , i = 1, . . . , n for
the correct values yi at discrete points ti are calculated by solving a linear system of
El objetivo es reemplazar los y , y ; : : : ; y reales de la trayectoria por sus
equations.
1 2 n
aproximaciones por diferencias
After the substitutions, finitas,
there are wi . situations. If the original boundary value
two possible
problem was linear, then the resulting system of equations is linear and can be solved by
Gaussian elimination or iterative methods. If the original problem was nonlinear, then
Si el
theproblema de contorno
algebraic system original
is a system es linealequations,
of nonlinear el problema se convierte
requiring entonces
more sophisticated
en approaches.
resolver unWesistema de aecuaciones
begin with lineales; si no es lineal, en lo propio.
linear example.
2
1C 4h 2 w1 C w2 D 0
4h2 2 w2 C w3 D 0
w1 C
4h2 2 w3 C 3 D 0:
w2 C
Las diferencias son O.10 2/. Para obtener más precisión habría que aumentar n.
12/34
8
00
<y D y
ˆ
ˆ y2
y.0/ D 1
ˆ
ˆ
: y.1/ D 4:
para 2 i n 1.
La función vectorial es
2 C h2 w1 C h2 w12 C w2
2 3
ya
2 C h2 w2 C h2 w22 C w3 7
6 w1
6 7
f .wk / D 6
6 :: 7;
7
6 : 7
2 C h2 wn 1 C h2 wn2 1 C wn 5
4wn 2
wn 1 2 C h2 wn C h2 wn2 C yb
donde ya D 1 y yb D 4.
22h2w 2 C h2
1 0 0
3
1
: :: :: ::
2h2 w1 2 C h2
6 1 : : 7
:: 7:
La Jacobiana: 6 0 1 : 1 0
:: :: ::
4 5
: 2h2 w1 h2
: : 2C 1
2h2 wn 2 C h2
0 0 1
Cada fila i es la derivada parcial de la ecuación i de f con respecto a cada wj .
15/34
end
close all, plot ([a a+(1:n)*h b],[ya w1’ yb]);
2.5
end
function y=f7(w,h,bv,n) 2
y=zeros(n,1);
y(1)=bv(1)-(2+h^2)*w(1)+h^2*w(1)^2+w(2);
y(n)=w(n-1)-(2+h^2)*w(n)+h^2*w(n)^2+bv(2); function a=jac(w,h,n) 1.5
a=zeros(n,n);
for i=2:n-1 for i=1:n
y(i)=w(i-1)-(2+h^2)*w(i)+h^2*w(i)^2+w(i+1); a(i,i)=2*h^2*w(i)-2-h^2;
end 1
end 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
for i=1:n-1
end a(i,i+1)=1;
a(i+1,i)=1;
end
end
Método de colocación
8
00
< y D 4y
ˆ
ˆ
Resolvamos la ecuación y.0/ D 1
ˆ
ˆ
: y.1/ D 3:
Pn Pn j 1
La solución será de la forma y.t / D j D1 cj j .t / D j D1 cj t .
Se formularán n ecuaciones con las n incógnitas c1; : : : ; cn. La primera y la 19/34
En el ejemplo,
n h i
X j 3 j 1
j 1 j 2 ti 4ti cj D 0; i D 2; : : : ; n 1:
j D1
Las n ecuaciones forman un sistema Ac D b, donde la matriz de coeficientes 20/34
y b D Œ1 0 0 0 3T .
3
Exacta
y(t)=1+2t
2 3
y(t)=1-0.1886t+1.0273t +1.1613t
2.5
1.5
0.5
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Tiempo
22/34
El ejemplo que hemos utilizado para introducir el método era lineal, pues así lo
era la ecuación diferencial. Si fuese no lineal, habría que utilizar el método de
Newton-Raphson para resolver el sistema de ecuaciones no lineales que resultase.
Igual que hemos utilizado monomios como funciones base para aplicar el
método, se puede recurrir a cualesquiera otras: polinomios de Chebyshev,
funciones trigonométricas, etc.
23/34
8
00 0
< y D f .t; y; y /
ˆ
ˆ
y.a/ D y
a
ˆ
ˆ
: y.b/ D y ;
b
1. hy1; y2i 0;
2. h˛y1 C ˇy2; zi D ˛hy1; zi C ˇhy2; zi, siendo ˛ y ˇ escalares;
3. hy1; y2i D hy2; y1i.
1º- Minimizar el vector residuo r forzando a que sea ortogonal, en el sentido del
producto interior anterior, a un conjunto de R b n C00 2 funciones
base 0.t /,
1.t /; : : :, nC1.t /. Es decir forzar a que a y f i dt D 0, o que
Z b Z b
00
y .t/i .t/ dt D f .t; y; y 0 /i .t/ dt forma débil
a a
para cada 0 i n C 1.
2º- Utilizar integración por partes para eliminar las segundas derivadas.
Teniendo en cuenta que
Z b ˇb
Z b
00
y .t/i .t/ dt D i .t/y 0 .t/ˇa y 0 .t/i0 .t/ dt
a a Z b
D i .b/y 0 .b/ i .a/y 0 .a/ y 0 .t/i0 .t/ dt:
a
f .t; y; y 0 /i .t/ dt D i .b/y 0 .b/ i .a/y 0 .a/ y 0 .t/i0 .t/ dt:
a a
27/34
Para ello, en los puntos t0 < t1 < < tn < tnC1 sobre el eje t, para
i D 1; : : : ; n, se define
8
t ti 1
ˆ
ˆ t ti 1
para ti 1 < t ti
< i
ˆ
ˆ
ti C1 t
i .t / D para ti < t < ti C1
ˆ tiC1 ti
ˆ
ˆ
ˆ
:0 en otros casos.
28/34
Y, también,
8 8
t1 t t tn
<
ti t0
para t0 t < t1 <
tnC1 tn
para tn < t tnC1
0.t/ D y nC1.t / D
:0 en otros casos7.3 Collocation and the: 0 ElementenMethod
Finite otros |casos.
369
y
0 1 2 n–1 n n+1
1
t
t0 t1 t2 t 3 ... tn–1 tn tn+1
Figure 7.10 Piecewise-linear B-splines used as finite elements. Each φi (t), for
1 ≤ i ≤ n, has support on the interval from ti−1 to ti+1 .
1 si i D j
Estas funciones satisfacen que i .tj / D
0 si i ¤ j:
for each i that can be solved for the ci in the functional form
n+1
y(t) = c φ (t). (7.23)
29/34
S.t/ es una función lineal por tramos que interpola los puntos .ti ; ci /. Además,
los ci son las soluciones en los puntos ti de la aproximación de la ecuación
diferencial.
30/34
nC1
X
y.b/ D ci i .b/ D cnC1nC1.b/ D cnC1:
i D0
b h 2
t 2
Z Z
2
i .t/ dt D 2 dt D h
a 0 h 3
b h
1 1 1
Z Z
i0 .t/iC1
0
.t/ dt D dt D
a 0 h h h
b h 2
1 2
Z Z
0 2
i .t/ dt D 2 dt D :
a 0 h h
8
00
< y D 4y
ˆ
ˆ
Ejemplo Mediante elementos finitos, resolvamos y.0/ D 1
ˆ
ˆ
: y.1/ D 3:
nC1
i Z 1 Z 1
D cj 4 i .t/j .t/ dt C j0 .t/i0 .t/ dt :
0 0
j D0
Usando las expresiones de las B-splines para i D 1; : : : ; n y teniendo en cuenta 33/34
que c0 D f .a/ y cnC1 D f .b/, las ecuaciones que resultan son estas:
2 1
8 2
2 1
3
h h
c0 C 3
hC h
c1 C 3
h h
c2 D 0
2 1
8 2
2 1
3
h h
c1 C 3
hC h
c1 C 3
h h
c1 D 0
::
: 0
2 1
8 2
2 1
3
h h
cn 1 C 3
hC h
cn C 3
h h
cnC1 D 0:
donde
8 2 2 1
˛ D hC y ˇD h :
3 h 3 h
Si recopilamos todo lo necesario en un fichero .m de Matlab para este caso: 34/34
function c=Galerkin_ef_1(inter,bv,n)
% Elementos finitos de ejemplo clase
% inter, intervalo de integración; bv, valores de contorno;
% n, número de pasos.
a=inter(1); b=inter(2); ya=bv(1); yb=bv(2);
h=(b-a)/(n+1);
alfa=(8/3)*h+2/h; beta=(2/3)*h-1/h;
e=ones(n,1);
M=spdiags([beta*e alfa*e beta*e],-1:1,n,n);
d=zeros(n,1); d(1)=-ya*beta; d(n)=-yb*beta;
c=M\d;
end
Las diferencias son O.10 2/. Para obtener más precisión habría que aumentar n.