0% found this document useful (0 votes)
58 views24 pages

Tarea 5

This document contains code to solve a numerical methods problem involving heat transfer. It defines a function to calculate temperature values on a grid using an iterative method. The code initializes temperature values, calculates new values over 2000 iterations, and outputs error. It then generates plots showing the temperature distribution and heat flux vectors. In 3 sentences: The code sets up and solves a heat transfer problem on a grid using an iterative method to calculate temperature values. It outputs the temperature matrix, error, and generates plots of the temperature distribution and heat flux vectors. The numerical method calculates new temperature values over 2000 iterations to minimize error between iterations.

Uploaded by

Mito Shi Toa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views24 pages

Tarea 5

This document contains code to solve a numerical methods problem involving heat transfer. It defines a function to calculate temperature values on a grid using an iterative method. The code initializes temperature values, calculates new values over 2000 iterations, and outputs error. It then generates plots showing the temperature distribution and heat flux vectors. In 3 sentences: The code sets up and solves a heat transfer problem on a grid using an iterative method to calculate temperature values. It outputs the temperature matrix, error, and generates plots of the temperature distribution and heat flux vectors. The numerical method calculates new temperature values over 2000 iterations to minimize error between iterations.

Uploaded by

Mito Shi Toa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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')

You might also like