METODOS NUMERICOS 2
TAREA 5
Encala Rojas Luis 15130145
%definimos la funcion
clc
clear
dx=10;
dy=10;
NX=5;
NY=5;
LM=1.17;
%fronteras
Boundary_Left = NaN; Boundary_Right = [50 37.5 25 12.5 0];
Boundary_Top = [0 12.5 25 37.5 50]; Boundary_Bottom = NaN;
Xst = 2; Xnd = NX-1;
Yst = 2; Ynd = NY-1;
if isnan(Boundary_Left)
Xst=1;
end
if isnan(Boundary_Bottom)
Ynd=NY;
end
T=nan(NX,NY);
T(NX,:) = Boundary_Bottom;
T(:,NY) = Boundary_Right;
T(:,1) = Boundary_Left;
T(1,:) = Boundary_Top;
%funcion solucion \\
T(isnan(T)) = rand(1);
for Iter =1:2000
T_old = T;
for i=Yst:Ynd
for j=Xst:Xnd
if j==1
if i==Ynd
T(i,j) = 0.25*( 2*T(i-1,j) + 2*T(i,j+1) );
else
T(i,j) = 0.25*( T(i+1,j) + T(i-1,j) + 2*T(i,j+1) );
end
elseif i==1
T(i,j) = 0.25*( 2*T(i+1,j) + T(i,j-1) + T(i,j+1) );
elseif i==Ynd
T(i,j) = 0.25*( 2*T(i-1,j) + T(i,j-1) + T(i,j+1) );
else
T(i,j) = 0.25*( T(i+1,j) + T(i,j+1) + T(i-1,j) + T(i,j-1));
end
T(i,j) = LM*T(i,j) + (1-LM)*T_old(i,j);
end
end
Error = 100.*sum(sum( abs((T_old(Yst:Ynd,Xst:Xnd)-T(Yst:Ynd,Xst:Xnd))./T(Yst:Ynd,Xst:Xnd))));
disp('MATRIZ DE TEMPERATURAS')
disp(T)
disp('MATRIZ DE ERRORES')
disp(abs((T_old(Yst:Ynd,Xst:Xnd)-T(Yst:Ynd,Xst:Xnd))./T(Yst:Ynd,Xst:Xnd)))
disp('ERROR');
disp(Error);
if Error <1
break
end
end
%Plot de distribucion de tenmperatura
TIT = 'distribucion de tenmperatura'; XL = 't'; YL = 'y';
figure('units','normalized','Position',[0.1 0.1 0.7 0.8])
imagesc(T)
grid on
box on
hold on
xlabel('X')
ylabel('Y')
title(TIT)
cc= colorbar;
xlabel(cc,'^\circC')
colormap(jet(30))
for i=1:NX
for j=1:NY
plot(i,j,'ko','LineWidth',3)
text(i+0.1,j+0.1,num2str(T(j,i),4),'FontSize',15)
end
end
set(gca,'FontSize',15)
print(['Plot1.png'],'-dpng')
%flujo de calor
k=0.49;
Qx =zeros(3);
Qy =zeros(3);
for i=1:3
for j=1:3
Qx(i,j)= -k*(T(i+1,j+2)-T(i+1,j))/(2*dx);
Qy(i,j) = -k*(T(i,j+1)-T(i+2,j+1))/(2*dy);
QQ = sqrt(Qx.^2+Qy.^2);
end
end
disp("los flujos son"),Qx,Qy,QQ
%plot flujos
QQ = sqrt(Qx.^2+Qy.^2);
TIT = 'distribucion de flujos ';
figure('units','normalized','Position',[0.1 0.1 0.7 0.8])
imagesc(sqrt(Qx.^2+Qy.^2))
grid on
box on
hold on
xlabel('X')
ylabel('Y')
title(TIT)
cc= colorbar;
quiver((Qx),((Qy)),'LineWidth',3,'color','k')