You are on page 1of 39

UNIVERSIDAD NACIONAL DE SAN CRISTOBAL DE HUAMANGA

Grupo: floyd warshall

Integrantes:
Asto Berrocal, Richar
Ircaaupa Huamani, Angel
Sosa lozano, Elvis

Programacin: ecuacin de Laplace en matlab (pag:697)

function U=dirich(f1,f2,f3,f4,a,b,h,tol,max1)

%Datos
% - f1,f2,f3,f4 son las funciones en el contorno almacenadas como cadenas
de caracteres
% - a y b son los extremos superiores de los intervalos [0,a] y [0,b]
% - h es el incremento
% - tol es la tolerancia
% resultado
% - U es la matriz en la que se almacena la solucin numrica
% Inicializacin de los parmetros y de U
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;
% Parmetro de sobre relajacin
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');

F1.m

%Condicion de frontera en y=0


function ux0=f1(x)
ux0=0;

F2.m

%Condicion de frontera en y=0.5


function ux3=f2(x)
ux3=200*y;

F3.m

%Condicion de frontera en x=0


function u0y=f3(y)
u0y=0;

F4.m

%Condicion de frontera en x=0.5


function u3y=f4(y)
u3y=200*y;
U=dirich('f1','f2','f3', 'f4',0.5,0.5,0.1,0.2,10 )
mesh(U)

U=

35.0000 90.0000 90.0000 90.0000 90.0000 45.0000


70.0000 73.1846 69.8864 61.9312 44.5453

70.0000 62.8435 54.4308 43.2937 26.2496

70.0000 53.7632 41.6987 30.5625 17.1571

70.0000 40.4542 28.0435 20.1038 11.8132

40.0000 10.0000 10.0000 10.0000 10.0000 5.0000

Programacin: metodo de Crank-Nicolson (pag:582)

%% iniciamos
clc
clear all
%% Definiciones
% ejes
dx = .1;
dt = 0.01;
num_x_puntos = 5;
num_t_puntos = 10;
x_eje = linspace(0, 2, num_x_puntos);
t_eje = linspace(0, 10, num_t_puntos);
z_eje = linspace(-2, 2, 20);
% Condiciones
% Una condicin inicial
% Condiciones de frontera para la base de la placa
inicial =(80-10*num_x_puntos)*ones(1,num_x_puntos
% Lmites de temperatura izquierda y derecha
T_iz = 200;
T_de = 68;
%% metodo de Crank-Nicolson
% Construccion de la matriz de respuesta
T = zeros(num_t_puntos, num_x_puntos);
% Las columnas son las coordenadas x , las filas son coordenadas T
% Aplicando las condiciones de contorno a la matriz
T(1,:) = inicial;
T(:,1) = T_iz;
T(:,end) = T_de;
% solucionando....
a = 1;
r = (a*dt)/(2*dx^2);
% diagonales para M
central = ones(num_x_puntos - 2, 1) * (1 + 2*r);
superior = ones(num_x_puntos - 3, 1) * (-r);
inferior = ones(num_x_puntos - 3, 1) * (-r);
M = diag(central) + diag(superior, 1) + diag(inferior, -1);
% Mantener la solucin para la temperatura en la fila, iterando....
for i = 2:num_t_puntos
t_t = [0; T(i-1, 2:end-1)'; 0];

t_reg = t_t(2:end-1);
t_minus = t_t(1:end-2, :);
t_plus = t_t(3:end, :);
b = r*t_plus + (1-2*r)*t_reg + r*t_minus;
b(1) = b(1) + r*T_iz;
b(end) = b(end) + r*T_de;
% Solucionando la ecuacin
t = [T_iz; M \ b; T_de]';
T(i, :) = t
end
figure
% Plateando la solucin
surf(x_eje, t_eje, T, 'EdgeColor', 'None')
xlabel('x')
ylabel('Tiempo (s)')
zlabel('Temperatura')

T=

200.0000 30.0000 30.0000 30.0000 68.0000


200.0000 67.6429 40.5714 34.6429 68.0000
200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

T=

200.0000 30.0000 30.0000 30.0000 68.0000


200.0000 67.6429 40.5714 34.6429 68.0000
200.0000 73.6837 54.1633 40.6837 68.0000
200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

T=

200.0000 30.0000 30.0000 30.0000 68.0000


200.0000 67.6429 40.5714 34.6429 68.0000
200.0000 73.6837 54.1633 40.6837 68.0000
200.0000 78.4300 59.5569 45.4300 68.0000
200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

T=

200.0000 30.0000 30.0000 30.0000 68.0000


200.0000 67.6429 40.5714 34.6429 68.0000
200.0000 73.6837 54.1633 40.6837 68.0000
200.0000 78.4300 59.5569 45.4300 68.0000
200.0000 80.6491 63.0396 47.6491 68.0000
200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

T=

200.0000 30.0000 30.0000 30.0000 68.0000


200.0000 67.6429 40.5714 34.6429 68.0000
200.0000 73.6837 54.1633 40.6837 68.0000
200.0000 78.4300 59.5569 45.4300 68.0000
200.0000 80.6491 63.0396 47.6491 68.0000
200.0000 81.9612 64.8051 48.9612 68.0000
200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

T=

200.0000 30.0000 30.0000 30.0000 68.0000


200.0000 67.6429 40.5714 34.6429 68.0000
200.0000 73.6837 54.1633 40.6837 68.0000
200.0000 78.4300 59.5569 45.4300 68.0000
200.0000 80.6491 63.0396 47.6491 68.0000
200.0000 81.9612 64.8051 48.9612 68.0000

200.0000 82.6531 65.8071 49.6531 68.0000


200.0000

0 68.0000

200.0000

0 68.0000

200.0000

0 68.0000

T=

200.0000 30.0000 30.0000 30.0000 68.0000


200.0000 67.6429 40.5714 34.6429 68.0000
200.0000 73.6837 54.1633 40.6837 68.0000
200.0000 78.4300 59.5569 45.4300 68.0000
200.0000 80.6491 63.0396 47.6491 68.0000
200.0000 81.9612 64.8051 48.9612 68.0000
200.0000 82.6531 65.8071 49.6531 68.0000
200.0000 83.0382 66.3456 50.0382 68.0000
200.0000

0 68.0000

200.0000

0 68.0000

T=

200.0000 30.0000 30.0000 30.0000 68.0000


200.0000 67.6429 40.5714 34.6429 68.0000
200.0000 73.6837 54.1633 40.6837 68.0000
200.0000 78.4300 59.5569 45.4300 68.0000

200.0000 80.6491 63.0396 47.6491 68.0000


200.0000 81.9612 64.8051 48.9612 68.0000
200.0000 82.6531 65.8071 49.6531 68.0000
200.0000 83.0382 66.3456 50.0382 68.0000
200.0000 83.2471 66.6426 50.2471 68.0000
200.0000

0 68.0000

T=

200.0000 30.0000 30.0000 30.0000 68.0000


200.0000 67.6429 40.5714 34.6429 68.0000
200.0000 73.6837 54.1633 40.6837 68.0000
200.0000 78.4300 59.5569 45.4300 68.0000
200.0000 80.6491 63.0396 47.6491 68.0000
200.0000 81.9612 64.8051 48.9612 68.0000
200.0000 82.6531 65.8071 49.6531 68.0000
200.0000 83.0382 66.3456 50.0382 68.0000
200.0000 83.2471 66.6426 50.2471 68.0000
200.0000 83.3618 66.8044 50.3618 68.0000

Programacin: mtodo de Crank-Nicolson (pag:107)

%% iniciamos
clc
clear all
%close all
%% Definiciones
% ejes
dx = .1;
dt = 0.01;
num_x_puntos = 5;
num_t_puntos = 10;
x_eje = linspace(0, 2, num_x_puntos);
t_eje = linspace(0, 10, num_t_puntos);
z_eje = linspace(-2, 2, 20);
% Condiciones
% Una condicin inicial
%se aplican segn sea necesario

% Condiciones de frontera para la base de la placa


%[din1, din2] = size(inicial);
inicial =100*ones(1,num_x_puntos);
%inicial=100*zeros(21)
% Lmites de temperatura izquierda y derecha
T_iz = 0;
T_de = 0;
%% metodo de Crank-Nicolson
% Construccion de la matriz de respuesta
T = zeros(num_t_puntos, num_x_puntos);
% Las columnas son las coordenadas x , las filas son coordenadas T
% Aplicando las condiciones de contorno a la matriz
T(1,:) = inicial;
T(:,1) = T_iz;
T(:,end) = T_de;
% solucionando....
a = 1;
r = (a*dt)/(2*dx^2);
% diagonales para M
central = ones(num_x_puntos - 2, 1) * (1 + 2*r);
superior = ones(num_x_puntos - 3, 1) * (-r);
inferior = ones(num_x_puntos - 3, 1) * (-r);
M = diag(central) + diag(superior, 1) + diag(inferior, -1);

% Mantener la solucin para la temperatura en la fila, iterando....


for i = 2:num_t_puntos
t_t = [0; T(i-1, 2:end-1)'; 0];
t_reg = t_t(2:end-1);
t_minus = t_t(1:end-2, :);
t_plus = t_t(3:end, :);
b = r*t_plus + (1-2*r)*t_reg + r*t_minus;
b(1) = b(1) + r*T_iz;
b(end) = b(end) + r*T_de;
% Solucionando la ecuacin :
t = [T_iz; M \ b; T_de]';
T(i, :) = t
end
figure
% Ploteando la solution
surf(x_eje, t_eje, T, 'EdgeColor', 'None')
xlabel('x')
ylabel('Tiempo (s)')
zlabel('Temperatura')

T=

0 100.0000 100.0000 100.0000


0 42.8571 71.4286 42.8571
0

0
0

T=

0 100.0000 100.0000 100.0000

0 42.8571 71.4286 42.8571

0 26.5306 34.6939 26.5306

T=

0 100.0000 100.0000 100.0000

0 42.8571 71.4286 42.8571

0 26.5306 34.6939 26.5306

0 13.7026 20.1166 13.7026

T=

0 100.0000 100.0000 100.0000

0 42.8571 71.4286 42.8571

0 26.5306 34.6939 26.5306

0 13.7026 20.1166 13.7026

0 7.7051 10.7039 7.7051


0

T=

0 100.0000 100.0000 100.0000

0 42.8571 71.4286 42.8571

0 26.5306 34.6939 26.5306

0 13.7026 20.1166 13.7026

0 7.7051 10.7039 7.7051

0 4.1590 5.9321 4.1590

T=

0 100.0000 100.0000 100.0000

0 42.8571 71.4286 42.8571

0 26.5306 34.6939 26.5306

0 13.7026 20.1166 13.7026

0 7.7051 10.7039 7.7051

0 4.1590 5.9321 4.1590

0 2.2890 3.2240 2.2890


0

T=

0 100.0000 100.0000 100.0000

0 42.8571 71.4286 42.8571

0 26.5306 34.6939 26.5306

0 13.7026 20.1166 13.7026

0 7.7051 10.7039 7.7051

0 4.1590 5.9321 4.1590

0 2.2890 3.2240 2.2890

0 1.2481 1.7686 1.2481

T=

0 100.0000 100.0000 100.0000

0 42.8571 71.4286 42.8571

0 26.5306 34.6939 26.5306

0 13.7026 20.1166 13.7026

0 7.7051 10.7039 7.7051

0 4.1590 5.9321 4.1590

0 2.2890 3.2240 2.2890

0 1.2481 1.7686 1.2481

0 0.6836 0.9659 0.6836

T=

0 100.0000 100.0000 100.0000

0 42.8571 71.4286 42.8571

0 26.5306 34.6939 26.5306

0 13.7026 20.1166 13.7026

0 7.7051 10.7039 7.7051

0 4.1590 5.9321 4.1590

0 2.2890 3.2240 2.2890

0 1.2481 1.7686 1.2481

0 0.6836 0.9659 0.6836

0 0.3736 0.5286 0.3736

Programacin: metodo de Crank-Nicolson (pag:136)

%% iniciamos
clc
clear all
%% Definiciones
% ejes
dx = .1;
dt = 0.01;
num_x_puntos = 10;
num_t_puntos = 10;
x_eje = linspace(0, 2, num_x_puntos);
t_eje = linspace(0, 10, num_t_puntos);
z_eje = linspace(-2, 2, 20);
% Condiciones
% Una condicin inicial
%se aplican segn sea necesario

%[din1, din2] = size(inicial);


inicial =sin(pi*num_x_puntos/2)*ones(1,num_x_puntos);
% Lmites de temperatura izquierda y derecha
T_iz = sin(pi*num_x_puntos/2);
T_de = sin(pi*num_x_puntos/2);
%% metodo de Crank-Nicolson
% Construccion de la matriz de respuesta
T = zeros(num_t_puntos, num_x_puntos);
% Las columnas son las coordenadas x , las filas son coordenadas T
% Aplicando las condiciones de contorno a la matriz
T(1,:) = inicial;
T(:,1) = T_iz;
T(:,end) = T_de;
% solucionando....
a = 1;
r = (a*dt)/(2*dx^2);
% diagonales para M
central = ones(num_x_puntos - 2, 1) * (1 + 2*r);
superior = ones(num_x_puntos - 3, 1) * (-r);
inferior = ones(num_x_puntos - 3, 1) * (-r);
M = diag(central) + diag(superior, 1) + diag(inferior, -1);
% Mantener la solucin para la temperatura en la fila, iterando....

for i = 2:num_t_puntos
t_t = [0; T(i-1, 2:end-1)'; 0];
t_reg = t_t(2:end-1);
t_minus = t_t(1:end-2, :);
t_plus = t_t(3:end, :);
b = r*t_plus + (1-2*r)*t_reg + r*t_minus;
b(1) = b(1) + r*T_iz;
b(end) = b(end) + r*T_de;
% Solucionando la ecuacion:
t = [T_iz; M \ b; T_de]';
T(i, :) = t
end
figure
% Ploteando la solucion
surf(x_eje, t_eje, T, 'EdgeColor', 'None')
xlabel('x')
ylabel('Tiempo (s)')
zlabel('Temperatura')

T=

1.0e-015 *

0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123
0.6123 0.4482 0.5683 0.6003 0.6083 0.6083 0.6003 0.5683 0.4482 0.6123
0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

T=

1.0e-015 *

0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123
0.6123 0.4482 0.5683 0.6003 0.6083 0.6083 0.6003 0.5683 0.4482 0.6123
0.6123 0.4227 0.5103 0.5699 0.5929 0.5929 0.5699 0.5103 0.4227 0.6123
0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

T=

1.0e-015 *

0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123
0.6123 0.4482 0.5683 0.6003 0.6083 0.6083 0.6003 0.5683 0.4482 0.6123
0.6123 0.4227 0.5103 0.5699 0.5929 0.5929 0.5699 0.5103 0.4227 0.6123
0.6123 0.4014 0.4831 0.5383 0.5670 0.5670 0.5383 0.4831 0.4014 0.6123
0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

T=

1.0e-015 *

0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123
0.6123 0.4482 0.5683 0.6003 0.6083 0.6083 0.6003 0.5683 0.4482 0.6123
0.6123 0.4227 0.5103 0.5699 0.5929 0.5929 0.5699 0.5103 0.4227 0.6123
0.6123 0.4014 0.4831 0.5383 0.5670 0.5670 0.5383 0.4831 0.4014 0.6123
0.6123 0.3889 0.4603 0.5124 0.5393 0.5393 0.5124 0.4603 0.3889 0.6123
0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

T=

1.0e-015 *

0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123
0.6123 0.4482 0.5683 0.6003 0.6083 0.6083 0.6003 0.5683 0.4482 0.6123
0.6123 0.4227 0.5103 0.5699 0.5929 0.5929 0.5699 0.5103 0.4227 0.6123
0.6123 0.4014 0.4831 0.5383 0.5670 0.5670 0.5383 0.4831 0.4014 0.6123
0.6123 0.3889 0.4603 0.5124 0.5393 0.5393 0.5124 0.4603 0.3889 0.6123
0.6123 0.3787 0.4422 0.4888 0.5135 0.5135 0.4888 0.4422 0.3787 0.6123
0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

T=

1.0e-015 *

0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123
0.6123 0.4482 0.5683 0.6003 0.6083 0.6083 0.6003 0.5683 0.4482 0.6123
0.6123 0.4227 0.5103 0.5699 0.5929 0.5929 0.5699 0.5103 0.4227 0.6123
0.6123 0.4014 0.4831 0.5383 0.5670 0.5670 0.5383 0.4831 0.4014 0.6123
0.6123 0.3889 0.4603 0.5124 0.5393 0.5393 0.5124 0.4603 0.3889 0.6123
0.6123 0.3787 0.4422 0.4888 0.5135 0.5135 0.4888 0.4422 0.3787 0.6123
0.6123 0.3703 0.4265 0.4681 0.4901 0.4901 0.4681 0.4265 0.3703 0.6123
0.6123

0 0.6123

0.6123

0 0.6123

0.6123

0 0.6123

T=

1.0e-015 *

0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123
0.6123 0.4482 0.5683 0.6003 0.6083 0.6083 0.6003 0.5683 0.4482 0.6123
0.6123 0.4227 0.5103 0.5699 0.5929 0.5929 0.5699 0.5103 0.4227 0.6123
0.6123 0.4014 0.4831 0.5383 0.5670 0.5670 0.5383 0.4831 0.4014 0.6123

0.6123 0.3889 0.4603 0.5124 0.5393 0.5393 0.5124 0.4603 0.3889 0.6123
0.6123 0.3787 0.4422 0.4888 0.5135 0.5135 0.4888 0.4422 0.3787 0.6123
0.6123 0.3703 0.4265 0.4681 0.4901 0.4901 0.4681 0.4265 0.3703 0.6123
0.6123 0.3629 0.4127 0.4497 0.4693 0.4693 0.4497 0.4127 0.3629 0.6123
0.6123

0 0.6123

0.6123

0 0.6123

T=

1.0e-015 *

0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123
0.6123 0.4482 0.5683 0.6003 0.6083 0.6083 0.6003 0.5683 0.4482 0.6123
0.6123 0.4227 0.5103 0.5699 0.5929 0.5929 0.5699 0.5103 0.4227 0.6123
0.6123 0.4014 0.4831 0.5383 0.5670 0.5670 0.5383 0.4831 0.4014 0.6123
0.6123 0.3889 0.4603 0.5124 0.5393 0.5393 0.5124 0.4603 0.3889 0.6123
0.6123 0.3787 0.4422 0.4888 0.5135 0.5135 0.4888 0.4422 0.3787 0.6123
0.6123 0.3703 0.4265 0.4681 0.4901 0.4901 0.4681 0.4265 0.3703 0.6123
0.6123 0.3629 0.4127 0.4497 0.4693 0.4693 0.4497 0.4127 0.3629 0.6123
0.6123 0.3564 0.4006 0.4333 0.4508 0.4508 0.4333 0.4006 0.3564 0.6123
0.6123

T=

0 0.6123

1.0e-015 *

0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123 0.6123
0.6123 0.4482 0.5683 0.6003 0.6083 0.6083 0.6003 0.5683 0.4482 0.6123
0.6123 0.4227 0.5103 0.5699 0.5929 0.5929 0.5699 0.5103 0.4227 0.6123
0.6123 0.4014 0.4831 0.5383 0.5670 0.5670 0.5383 0.4831 0.4014 0.6123
0.6123 0.3889 0.4603 0.5124 0.5393 0.5393 0.5124 0.4603 0.3889 0.6123
0.6123 0.3787 0.4422 0.4888 0.5135 0.5135 0.4888 0.4422 0.3787 0.6123
0.6123 0.3703 0.4265 0.4681 0.4901 0.4901 0.4681 0.4265 0.3703 0.6123
0.6123 0.3629 0.4127 0.4497 0.4693 0.4693 0.4497 0.4127 0.3629 0.6123
0.6123 0.3564 0.4006 0.4333 0.4508 0.4508 0.4333 0.4006 0.3564 0.6123
0.6123 0.3507 0.3898 0.4189 0.4343 0.4343 0.4189 0.3898 0.3507 0.6123

You might also like