You are on page 1of 12

Para las funciones Elipticas:

a) Para la ecuacin de Laplace:

function w=Poisson(xl,xr,yb,yt,M,N)
% Ecuacin de Poisson por diferencias finitas
% Entrada: [xl,xr], tiempo[yb,yt], pasos M, tiempos N
f=@(x,y) 0; g1=@(x) log(x.^2+1); g2=@(x) log(x.^2+4);
g3=@(y) 2*log(y); g4=@(y) log(y.^2+1);
m=M+1; n=N+1; mn=m*n; close all
h=(xr-xl)/M; h2=h^2; k=(yt-yb)/N; k2=k^2;
x=xl+(0:M)*h; y=yb+(0:N)*k;
x=xl+(0:M)*h; y=yb+(0:N)*k;
for i=2:m-1

for j=2:n-1

A(i+(j-1)*m,i-1+(j-1)*m)=1/h2; A(i+(j-1)*m,i+1+(j-1)*m)=1/h2;
A(i+(j-1)*m,i+(j-1)*m)=-2/h2-2/k2;
A(i+(j-1)*m,i+(j-2)*m)=1/k2; A(i+(j-1)*m,i+j*m)=1/k2;

b(i+(j-1)*m)=f(x(i),y(j));
end
end

for i=1:m
j=1; A(i+(j-1)*m,i+(j-1)*m)=1; b(i+(j-1)*m)=g1(x(i));
j=n; A(i+(j-1)*m,i+(j-1)*m)=1; b(i+(j-1)*m)=g2(x(i));
end
for j=2:n-1
i=1; A(i+(j-1)*m,i+(j-1)*m)=1; b(i+(j-1)*m)=g3(y(j));
i=m; A(i+(j-1)*m,i+(j-1)*m)=1; b(i+(j-1)*m)=g4(y(j));

end
v=A/b;
w=reshape(v(1:mn),m,n);
mesh(x,y,w)
end

b) Segunda ecuacin de Laplace:

function w=Poisson_FEM_1(xl,xr,yb,yt,M,N)
% Ecuacin de Poisson por Elementos Finitos
% Entrada: [xl,xr], tiempo[yb,yt], pasos M, tiempos N
f=@(x,y) 0; r=@(x,y) 0; g1=@(x) log(x.^2+1); g2=@(x) log(x.^2+4); g3=@(y)
2*log(y); g4=@(y) log(y.^2+1);
m=M+1; n=N+1; mn=m*n; close all
h=(xr-xl)/M; h2=h^2; k=(yt-yb)/N; k2=k^2; hk=h*k;
x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j-1)*m)=g2(x(i));

end
for j=2:n-1

i=1; A(i+(j-1)*m,i+(j-1)*m)=1; b(i+(j-1)*m)=g3(y(j));

i=m; A(i+(j-1)*m,i+(j-1)*m)=1; b(i+(j-1)*m)=g4(y(j));

end

v=A\b;

w=reshape(v(1:mn),m,n);

mesh(x,y,w)
end
Ejm: Sea la ecuacin de Laplace:

2 2
(, ) + 2 (, ) = 0
2

(0, ) = 80; (, 0) = 20; (, 4) = 180;

(4, ) = 0

En un rectngulo de dimensin:[0 4]x[0 4]

Solucin por el mtodo de Ecuaciones Diferenciales

Parciales Elpticas: Tomaremos el siguiente

Algoritmo ya mencionado.

a) Para la ecuacin de Laplace:

w=Poisson(20,180,80,0,8,8)

w =Columns 1 through 8
0.0028 0.0039 0.0038 0.0036 0.0034 0.0032 0.0028
0.0021
0.0034 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
0.0038 0.0000 0 0 0 0 0 0.0000
0.0041 0.0000 0 0 0 0 0 0.0000
0.0043 0.0000 0 0 0 0 0 0.0000
0.0044 0.0000 0 0 0 0 0 0.0000
0.0046 0.0000 0 0 0 0 0 0.0000
0.0047 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001
0.0048 0.0039 0.0038 0.0036 0.0034 0.0032 0.0028 0.0021

Column 9

0.0028
0.0034
0.0038
0.0041
0.0043
0.0044
0.0046
0.0047
0.0048
b) Para la Segunda ecuacin de Laplace:

w=Poisson_FEM_1(180,20,80,0,8,8)

w =Columns 1 through 8

10.3859 8.4970 8.1887 7.8240 7.3778 6.8024 5.9915 4.6052

10.1504 2.1158 1.1594 1.0066 0.9382 0.8749 0.8808 1.6941

9.8833 1.3508 0.2825 0.1448 0.1231 0.1280 0.2479 1.3047

9.5751 1.2267 0.1697 0.0358 0.0201 0.0336 0.1654 1.2215

9.2104 1.1712 0.1520 0.0230 0.0085 0.0225 0.1510 1.1701

8.7642 1.1230 0.1565 0.0341 0.0197 0.0319 0.1523 1.1179

8.1890 1.1382 0.2563 0.1416 0.1224 0.1247 0.2217 1.0923


7.3784 1.8140 1.1262 1.0030 0.9375 0.8714 0.8481 1.3936

5.9940 8.4972 8.1890 7.8244 7.3784 6.8035 5.9940 4.6151

Column 9

10.3860

10.1505

9.8835

9.5753

9.2107

8.7647

8.1898

7.3803

6.0014
Para las funciones Parabolicas:
a) Para la ecuacin Parcial Parablica: METODO DE
CRANK-NICOLSON.

function w=Crank_Nicolson(xl,xr,yb,yt,M,N)
% Ecuacin del calor por Crank-Nicolson
% Entrada: [xl,xr], tiempo[yb,yt], pasos M, tiempos N
f=@(x)sin(2*pi*x).^2;
l=@(t)0*t;
r=@(t)0*t;
D=1;
h=(xr-xl)/M; k=(yt-yb)/N; m=M-1; n=N; close all
sigma=D*k/h/h;
a=diag(2+2*sigma*ones(m,1))+diag(-sigma*ones(m-1,1),1);
a=a+diag(-sigma*ones(m-1,1),-1);
b=diag(2-2*sigma*ones(m,1))+diag(sigma*ones(m-1,1),1);
b=b+diag(sigma*ones(m-1,1),-1);
lside=l(yb+(0:n)*k); rside=r(yb+(0:n)*k);
w(:,1)=f(xl+(1:m)*h);
for j=1:n
sides=[lside(j)+lside(j+1); zeros(m-2,1); rside(j)+rside(j+1)];
w(:,j+1)=a\(b*w(:,j)+sigma*sides);
end
w=[lside; w; rside]
x=(0:m+1)*h; t=(0:n)*k;
mesh(x,t,w)
view(60,30);axis([xl xr yb yt -1 1])
end
EJEMPLO:
SEA

2
(, ) 2 (, ) = 0

(, 0) = 4 ^2; Para 0 1

(0, ) = 0; (2, ) = 0; Para 0 2

w=Crank_Nicolson(xl,xr,yb,yt,M,N)
Tomando valores en:
Xl=0(Este valor es para cuando x=0);
Donde (, 0) = 4 ^2; Para 0 1
Xr=1;
yb=0;
yt=1;
M=10;
N=10;

w=Crank_Nicolson(0,1,0,1,10,10)

w =

Columns 1 through 8

0 0 0 0 0 0 0
0
0.3455 0.0455 -0.0057 0.0655 -0.0639 0.0684 -0.0629
0.0571
0.9045 -0.1826 0.2520 -0.1180 0.0953 -0.0600 0.0447
-0.0322
0.9045 -0.0691 0.2550 -0.1209 0.1166 -0.0814 0.0662
-0.0508
0.3455 0.4087 -0.0415 0.1005 -0.0390 0.0345 -0.0200
0.0148
0.0000 0.6856 -0.2272 0.2395 -0.1400 0.1104 -0.0772
0.0585
0.3455 0.4087 -0.0415 0.1005 -0.0390 0.0345 -0.0200
0.0148
0.9045 -0.0691 0.2550 -0.1209 0.1166 -0.0814 0.0662
-0.0508
0.9045 -0.1826 0.2520 -0.1180 0.0953 -0.0600 0.0447
-0.0322
0.3455 0.0455 -0.0057 0.0655 -0.0639 0.0684 -0.0629
0.0571
0 0 0 0 0 0 0
0

Columns 9 through 11

0 0 0
-0.0501 0.0435 -0.0372
0.0248 -0.0194 0.0157
0.0404 -0.0318 0.0252
-0.0101 0.0075 -0.0056
-0.0436 0.0333 -0.0255
-0.0101 0.0075 -0.0056
0.0404 -0.0318 0.0252
0.0248 -0.0194 0.0157
-0.0501 0.0435 -0.0372
0 0 0

w =

Columns 1 through 8

0 0 0 0 0 0 0
0
0.3455 0.0455 -0.0057 0.0655 -0.0639 0.0684 -0.0629
0.0571
0.9045 -0.1826 0.2520 -0.1180 0.0953 -0.0600 0.0447
-0.0322
0.9045 -0.0691 0.2550 -0.1209 0.1166 -0.0814 0.0662
-0.0508
0.3455 0.4087 -0.0415 0.1005 -0.0390 0.0345 -0.0200
0.0148
0.0000 0.6856 -0.2272 0.2395 -0.1400 0.1104 -0.0772
0.0585
0.3455 0.4087 -0.0415 0.1005 -0.0390 0.0345 -0.0200
0.0148
0.9045 -0.0691 0.2550 -0.1209 0.1166 -0.0814 0.0662
-0.0508
0.9045 -0.1826 0.2520 -0.1180 0.0953 -0.0600 0.0447
-0.0322
0.3455 0.0455 -0.0057 0.0655 -0.0639 0.0684 -0.0629
0.0571
0 0 0 0 0 0 0
0

Columns 9 through 11

0 0 0
-0.0501 0.0435 -0.0372
0.0248 -0.0194 0.0157
0.0404 -0.0318 0.0252
-0.0101 0.0075 -0.0056
-0.0436 0.0333 -0.0255
-0.0101 0.0075 -0.0056
0.0404 -0.0318 0.0252
0.0248 -0.0194 0.0157
-0.0501 0.0435 -0.0372
0 0 0
Para las funciones Hiperblicas:

a) Para la ecuacin Parcial Hiperblicas: METODO


DE LA HONDA.

function U = onda (f,g,a,b,c,n,m)


%'sin(pi*x)+sin(2*pi*x)','0',1,0.5,2,11,21
%Datos
% - f=u(x,0) se entra como una cadena de caracteres.
% - g=ut(x,0) se ingresa como una cadena de caracteres.
% - a y b son los extremos superiores de los intervalos [0,a] y [0,b]
% - c es la constante de la ecuacion de onda.
% - n y m es el numero de nodos en [0,a] y [0,b]
%Resultado
% - U es la matriz con los respectivos resultados.
format long g;
close all;
h=a/(n-1);
k=b/(m-1);
alfa=c*k/h;
alfa2=alfa^2;
alfa22=(alfa2)/2;
s1=1-alfa2;
s2=2*s1;
U=zeros(n,m);
%se calculan las primeras filas (j-esimo y (j-1)-esimo paso)
for i=2:n-1
x=h*(i-1);
U(i,1)=eval(f);
%f esta en funcion de x
x=h*i;
evaluar1=eval(f);
x=h*(i-2);
evaluar2=eval(f);
x=h*(i-1);
U(i,2)=s1*eval(f)+k*eval(g)+alfa22*(evaluar1+evaluar2);
end
%Calculos de las otras filas
for j=3:m
for i=2:(n-1)
U(i,j)=s2*U(i,j-1)+alfa2*(U(i-1,j-1)+U(i+1,j-1))-U(i,j-2);
end
end
U=U';

Ejemplo: Resolver la ecuacin de la onda por el

Mtodo de diferencias finitas para las ecuaciones


Parciales Hiperblicas.

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

(, 0) = sin( ) + sin(2 ) ;

(, ) = 0 0 1

(0, ) = 0; (1, ) = 0; Para 0 0.5

En la cual emplearemos el siguiente algoritmo


U = onda(f,g,a,b,c,n,m)

f(x)= (, 0) = sin( ) + sin(2 );


g(x)=0;
a=1;
b=0.5;
c=2;
n=11;
m=11;

U = onda ('sin(pi*x)+sin(2*pi*x)','0',1,0.5,2,11,11)
U =

Columns 1 through 4
0 0.896802246667421 1.53884176858763
1.7600735106701
0 0.769420884293813 1.32843787866876
1.53884176858763
0 0.43163563200134 0.769420884293813
0.94840112333371
0 -2.22044604925031e-16 0.0515988766662898
0.181635632001339
0 -0.380036755335051 -0.587785252292474
0.519420884293813
0 -0.587785252292474 -0.951056516295154
0.951056516295154
0 -0.571019760960103 -0.951056516295154
1.01942088429381
0 -0.36327126400268 -0.639384128958763
0.769420884293814
0 -0.0683643679986601 -0.18163563200134
0.360615871041237
0 0.18163563200134 0.210403889918866
0
0 0.278768257917526 0.36327126400268
0.142039521920206

Columns 5 through 8

1.53884176858763 1 0.36327126400268
0.142039521920206
1.38003675533505 0.951056516295153 0.428980239039897
1.11022302462516e-16
0.951056516295153 0.809016994374947 0.587785252292473
0.360615871041237
0.377381362373607 0.587785252292473 0.740652626376287
0.769420884293813
-0.181635632001341 0.309016994374947 0.769420884293813
1.01942088429381
-0.587785252292473 -6.66133814775094e-16 0.587785252292473
0.951056516295153
-0.769420884293814 -0.309016994374948 0.181635632001339
0.519420884293813
-0.740652626376288 -0.587785252292474 -0.377381362373608
0.181635632001341
-0.587785252292474 -0.809016994374948 -0.951056516295154
0.948401123333711
-0.428980239039897 -0.951056516295154 -1.38003675533505
1.53884176858763
-0.363271264002681 -1 -1.53884176858763
1.7600735106701
Columns 9 through 11
-0.36327126400268 -0.278768257917526 0
-0.210403889918866 -0.18163563200134 0
0.18163563200134 0.0683643679986599 0
0.639384128958763 0.36327126400268 0
0.951056516295154 0.571019760960103 0
0.951056516295153 0.587785252292473 0
0.587785252292473 0.38003675533505 0
-0.05159887666629 -6.66133814775094e-16 0
-0.769420884293814 -0.43163563200134 0
-1.32843787866876 -0.769420884293814 0
-1.53884176858763 -0.896802246667421 0

You might also like