Sie sind auf Seite 1von 9

4.

- Encontrar una solucin en la ecuacin de Laplace (f(x,y)=0) en la Regin


R={(x,y)R/0x4, 0y4} , cuyos valores de frontera son:
u(x,0)=10;
u(x,4)=160; para 0x4
u(0,y)=70
u(4,y)=0 ; para 0y4
Programa: dirich.m
function U = dirich( f1,f2,f3,f4,a,b,h,tol,max1 )
n=fix(a/h)+1;
m=fix(b/h)+1;
ave=(a*(feval(f1,0)+feval(f2,0))...
+b*(feval(f3,0)+feval(f4,0)))/(2*a+2*b);
U=ave*ones(n,m);
%condiciones de contorno
U(1,1:m)=feval(f3,0:h:(m-1)*h)';
U(n,1:m)=feval(f4,0:h:(m-1)*h)';
U(1:n,1)=feval(f1,0:h:(n-1)*h);
U(1:n,m)=feval(f2,0:h:(n-1)*h);
U(1,1)=(U(1,2)+U(2,1))/2;
U(1,m)=(U(1,m-1)+U(n,2))/2;
U(n,1)=(U(n-1,1)+U(n,2))/2;
U(n,m)=(U(n-1,m)+U(n,m-1))/2;
% Parametro de sobrerrelajacion
w=4/(2+sqrt(4-(cos(pi/(n-1))+cos(pi/(m-1)))^2));
err=1;
cnt=0;
while((err>tol)&(cnt<=max1))
err=0;
for j=2:(m-1),
for i=2:(n-1),
relx=w*(U(i,j+1)+U(i,j-1)+U(i+1,j)+U(i-1,j)...
-4*U(i,j))/4;
U(i,j)=U(i,j)+relx;
if(err<=abs(relx)), err=abs(relx);
end
end
end
cnt=cnt+1;
end
U=flipud(U');
end

Programa: f1.m
function ux0=f1(x)
ux0=10;

Programa: f2.m
function ux4=f2(x)
ux4=160;

Programa: f3.m
function u0y=f3(y)
u0y=70;

Programa: f4.m
function u4y=f4(y)
u4y=0;

Programa: stard.m
U=dirich('f1','f2','f3','f4',4,4,0.5,0.01,10)
mesh(U)
title('SOLUCION DE LA EQUACION DE LAPLACE','COLOR','b','FontSize',10)
xlabel('x','FontSize',10)
ylabel('y','FontSize',10)
zlabel('U(x,y)','FontSize',10)
ejex=0:0.5:4;
ejey=0:0.5:4;

>> stard
U=
Columns 1 through 8
35.0000
160.0000
70.0000
78.6069
70.0000
70.0000
70.0000
70.0000
70.0000
70.0000
40.0000
Column 9
80.0000
0
0
0
0
0
0
0
5.0000

160.0000 160.0000 160.0000 160.0000 160.0000 160.0000


111.1690 124.9378 128.7514 127.5405 121.8080 108.7248
89.7376
77.9508
69.9480
63.0699
54.9904
41.3897
10.0000

99.8307
82.1193
68.7723
57.3437
45.5114
30.5746
10.0000

102.5277
81.9252
65.6796
52.0235
39.1401
25.3956
10.0000

99.6026
77.3747
59.9981
45.9310
33.6304
21.8694
10.0000

90.9669
67.9727
51.0077
38.0716
27.5809
18.4533
10.0000

74.4841
52.5414
37.9885
27.7672
20.1676
14.3628
10.0000

45.7030
29.7206
20.6377
14.8413
10.9600
8.8306
10.0000

5.- Considrese el problema de determinar la distribucin de calor en estado estable, en una


placa metlica cuadrada delgada con las dimensiones 50 cm por 50 cm. Se conserva dos
fronteras adyacentes a 0 c, mientras el calor en las otras dos fronteras aumenta linealmente
de 0c en una esquina a 100c en el sitio donde ambos lados se encuentran. Sugerencia.Considere los lados con las condiciones de frontera cero a lo largo de los ejes x e y.
Programa: dirich.m
function U = dirich( f1,f2,f3,f4,a,b,h,tol,max1 )
n=fix(a/h)+1;
m=fix(b/h)+1;
ave=(a*(feval(f1,0)+feval(f2,0))...
+b*(feval(f3,0)+feval(f4,0)))/(2*a+2*b);
U=ave*ones(n,m);
%condiciones de contorno
U(1,1:m)=feval(f3,0:h:(m-1)*h)';
U(n,1:m)=feval(f4,0:h:(m-1)*h)';
U(1:n,1)=feval(f1,0:h:(n-1)*h);
U(1:n,m)=feval(f2,0:h:(n-1)*h);
U(1,1)=(U(1,2)+U(2,1))/2;
U(1,m)=(U(1,m-1)+U(n,2))/2;
U(n,1)=(U(n-1,1)+U(n,2))/2;
U(n,m)=(U(n-1,m)+U(n,m-1))/2;
% Parametro de sobrerrelajacion
w=4/(2+sqrt(4-(cos(pi/(n-1))+cos(pi/(m-1)))^2));
err=1;
cnt=0;
while((err>tol)&(cnt<=max1))
err=0;
for j=2:(m-1),
for i=2:(n-1),
relx=w*(U(i,j+1)+U(i,j-1)+U(i+1,j)+U(i-1,j)...
-4*U(i,j))/4;
U(i,j)=U(i,j)+relx;
if(err<=abs(relx)), err=abs(relx);
end
end
end
cnt=cnt+1;
end
U=flipud(U');
end

Programa: f1.m
function ux0=f1(x)
ux0=10;

Programa: f2.m
function ux4=f2(x)
ux4=100;

Programa: f3.m
function u0y=f3(y)
u0y=0;

Programa: f4.m
function u4y=f4(y)
u4y=100;

Programa: stard.m
U=dirich('f1','f2','f3','f4',50,50,0.5,0.01,10)
mesh(U)
title('SOLUCION DE LA EQUACION DE LAPLACE','COLOR','b','FontSize',10)
xlabel('x','FontSize',10)
ylabel('y','FontSize',10)
zlabel('U(x,y)','FontSize',10)
ejex=0:1:50;
ejey=0:1:50;

>> stard
U=
Columns 1 through 8
50.0000 100.0000 100.0000 100.0000 100.0000 100.0000 100.0000
100.0000
0 49.9736 69.8411 79.4663 85.2049 89.3989 93.0281 96.5149
0 30.0553 49.9109 62.7956 71.9358 79.3521 86.1928 93.0281
0 20.3655 36.9639 49.8563 60.3730 69.8651 79.3521 89.3989
0 14.5877 27.7797 39.3151 49.8380 60.3730 71.9358 85.2049
0 10.5185 20.3622 29.8455 39.3151 49.8563 62.7956 79.4663
0 6.6391 13.6292 20.3622 27.7797 36.9639 49.9109 69.8411
0 3.1829 6.6391 10.5185 14.5877 20.3655 30.0553 49.9736
0
0
0
0
0
0
0
0
Column 9
100.0000
100.0000
100.0000
100.0000
100.0000
100.0000
100.0000
100.0000
50.0000

6.- Resolver la ecuacin de Laplace:


u(x,y) + u(x,y) = 0
x
y
Con condiciones de frontera:
u(0,y) = 90
u(x,0) = 30
sobre el rectngulo [0, 4] x [0, 4]

u(x,4) = 190

Programa: dirich.m
function U = dirich( f1,f2,f3,f4,a,b,h,tol,max1 )
n=fix(a/h)+1;
m=fix(b/h)+1;
ave=(a*(feval(f1,0)+feval(f2,0))...
+b*(feval(f3,0)+feval(f4,0)))/(2*a+2*b);
U=ave*ones(n,m);
%condiciones de contorno
U(1,1:m)=feval(f3,0:h:(m-1)*h)';
U(n,1:m)=feval(f4,0:h:(m-1)*h)';
U(1:n,1)=feval(f1,0:h:(n-1)*h);
U(1:n,m)=feval(f2,0:h:(n-1)*h);
U(1,1)=(U(1,2)+U(2,1))/2;
U(1,m)=(U(1,m-1)+U(n,2))/2;
U(n,1)=(U(n-1,1)+U(n,2))/2;
U(n,m)=(U(n-1,m)+U(n,m-1))/2;
% Parametro de sobrerrelajacion
w=4/(2+sqrt(4-(cos(pi/(n-1))+cos(pi/(m-1)))^2));
err=1;
cnt=0;
while((err>tol)&(cnt<=max1))
err=0;
for j=2:(m-1),
for i=2:(n-1),
relx=w*(U(i,j+1)+U(i,j-1)+U(i+1,j)+U(i-1,j)...
-4*U(i,j))/4;
U(i,j)=U(i,j)+relx;
if(err<=abs(relx)), err=abs(relx);
end
end
end
cnt=cnt+1;
end
U=flipud(U');
end

u(4,y) = 0

Programa: f1.m
function ux0=f1(x)
ux0=30;

Programa: f2.m
function ux4=f2(x)
ux4=190;

Programa: f3.m
function u0y=f3(y)
u0y=90;

Programa: f4.m
function u4y=f4(y)
u4y=0;

Programa: stard.m
U=dirich('f1','f2','f3','f4',4,4,0.5,0.01,10)
mesh(U)
title('SOLUCION DE LA EQUACION DE LAPLACE','COLOR','b','FontSize',10)
xlabel('x','FontSize',10)
ylabel('y','FontSize',10)
zlabel('U(x,y)','FontSize',10)
ejex=0:0.5:4;
ejey=0:0.5:4;

>> stard
U=
Columns 1 through 8
45.0000
190.0000
90.0000
93.7802
90.0000
90.0000
90.0000
90.0000
90.0000
90.0000
60.0000
Column 9
95.0000
0
0
0
0
0
0
0
15.0000

190.0000 190.0000 190.0000 190.0000 190.0000 190.0000


135.6367 150.7877 154.7683 152.9715 145.8378 129.9466
111.7574
98.7109
90.0950
82.7208
74.6019
61.1140
30.0000

122.7383
103.1129
88.6231
76.6373
64.7702
50.0455
30.0000

125.2961 121.2757 110.4345 90.1675 55.1731


102.3871 96.3918 84.4528 65.1120 36.7414
84.7418 77.4433 65.8693 49.0794 26.6719
70.4459 62.7788 52.5123 38.6608 20.8581
57.6163 50.8227 42.7618 32.1993 18.1011
44.6422 40.1164 35.5449 29.2813 19.3448
30.0000 30.0000 30.0000 30.0000 30.0000

Das könnte Ihnen auch gefallen