Professional Documents
Culture Documents
Integrantes:
Asto Berrocal, Richar
Ircaaupa Huamani, Angel
Sosa lozano, Elvis
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
F2.m
F3.m
F4.m
U=
%% 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=
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=
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=
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=
0 68.0000
200.0000
0 68.0000
200.0000
0 68.0000
200.0000
0 68.0000
200.0000
0 68.0000
T=
0 68.0000
200.0000
0 68.0000
200.0000
0 68.0000
200.0000
0 68.0000
T=
0 68.0000
200.0000
0 68.0000
200.0000
0 68.0000
T=
0 68.0000
200.0000
0 68.0000
T=
0 68.0000
T=
%% 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
T=
0
0
T=
T=
T=
T=
T=
T=
T=
T=
%% 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
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