analytical solution for steady state 2d heat transfer
19 次查看(过去 30 天)
显示 更早的评论
analytical solution for a 2d steady state sqaure bar
my plot for 'analytical solution1' isnt symmetric so i have tried using anathor equation 'analytical solution2' and now it is showing new errors.pls help
here i am attaching my full code.
here input conditions a=5,b=5,nx=ny=5
clear all
close all
clc
%Solving the Steady State 2D Heat Conduction Equation
%Length of Domain in x and y directions (unit square)
Lx=input("enter value of a");
Ly=input("enter value of b");
%No. of grid points
nx=1+input("enter no.of grids along x direction");
ny=1+input("enter no.of grids along y direction");
%Creating the mesh
x=linspace(0,Lx,nx);
y=linspace(0,Ly,ny);
dx=x(2)-x(1);
dy=abs(y(2)-y(1));
%Initial Conditions
T=298*ones(nx,ny);
K1 = dy^2/(2*((dx)^2 + (dy^2)));
K2 = dx^2/(2*((dx^2) + (dy^2)));
%Boundary Conditions
T(1,:) = 0; %First row or Bottom row of nodes in the matrix
T(end,:) = 0; %Last row or Top row of nodes in the matrix
T(:,1) = 100; %First column or Left side column of nodes in the matrix
T(:,end) = 0; %Last column or Right side column of nodes in the matrix
T_old=T; %Initializing the values for T_old for the first loop
tol=1e-4; %tolerance limit to attain convergence
error=9e9; %initial error to execute while loop
%Code for Solvers
%Jacobi Method
count=1;
while(error>tol)
for i=2:(nx-1)
for j=2:(ny-1)
h =K1*(T_old(i-1,j)+T_old(i+1,j));
v = K2*(T_old(i,j-1)+T_old(i,j+1));
T(i,j) = h+v;
end
end
error=max(abs(T(i,j)-T_old(i,j)));
T_old=T;
count=count+1;
end
% Plotting the Results
figure(1)
[a,b] = contourf(x,y,T);
clabel(a,b); colorbar;
colormap(jet);
xlabel('X Axis');
ylabel('Y Axis');
text = sprintf('2D steady state Heat Conduction n No. of iterations: %d',count);
title(text);
%analytical sol1
a=Lx;
b=Ly;
TA=298*ones(nx,ny);
%Boundary Conditions
TA(1,:) = 0; %First row or Bottom row of nodes in the matrix
TA(end,:) = 0; %Last row or Top row of nodes in the matrix
TA(:,1) = 100; %First column or Left side column of nodes in the matrix
TA(:,end) = 0; %Last column or Right side column of nodes in the matrix
sum=0;
for f=2:(nx-1)
for g=2:(ny-1)
for n=0:10
th=((b-g)*(2*n+1)*pi)/a;
tg=((2*n+1)*pi*f)/a;
tj=((2*n+1)*pi*b)/a;
tr=1/(2*n+1);
sum=sum+(sin(tg)*sinh(th)*tr)/sinh(tj)
end
TA(f,g)= (((4*100)*sum)/pi);
sum=0;
end
end
figure(2)
[a,b] = contourf(x,y,TA);
clabel(a,b); colorbar;
colormap(jet);
xlabel('X Axis');
ylabel('Y Axis');
text = sprintf('2D Transient Heat Conduction using analytical Method n No. of iterations: %d',count);
title(text);
TAA=298*ones(nx,ny);
%analytical sol2
%Boundary Conditions
TAA(1,:) = 0; %First row or Bottom row of nodes in the matrix
TAA(end,:) = 0; %Last row or Top row of nodes in the matrix
TAA(:,1) = 100; %First column or Left side column of nodes in the matrix
TAA(:,end) = 0; %Last column or Right side column of nodes in the matrix
sumA=0;
for fA=2:(nx-1)
for gA=2:(ny-1)
for nA=1:10
thA=(gA*nA*pi)./a;
tgA=(nA*pi*fA)./a;
tjA=(nA* (pi)*b)/a;
trA=1/nA;
sumA=sumA+(sin(tgA)*sinh(thA)*trA*(1-(1^nA)))/sinh(tjA);
end
TAA(fA,gA)= (((2*100)*sumA)/pi);
sumA=0;
end
end
figure(3)
[a,b] = contourf(x,y,TAA);
clabel(a,b); colorbar;
colormap(jet);
xlabel('X Axis');
ylabel('Y Axis');
text = sprintf('2D Transient Heat Conduction using analytical Method n No. of iterations: %d',count);
title(text);
2 个评论
KSSV
2020-6-9
Repalce this line
tjA=(nA* (pi)*b)/a;
with
tjA=(nA* (pi)*b)./a;
By the way the variable a got overwritten.
回答(1 个)
Abhishek Kumar
2020-12-13
Hi Niranjan, having run your code i see that you are getting the above error, when you try to display variable "b", you find that it is of contour type
>> b
b =
Contour with properties:
LineColor: [0 0 0]
LineStyle: '-'
LineWidth: 0.5000
Fill: on
LevelList: [0 10 20 30 40 50 60 70 80 90 100]
XData: [0 14.3333 28.6667 43]
YData: [0 7.6667 15.3333 23]
ZData: [4×4 double]
Show all properties
and thus you can't use the operator '*' directly with it but you can access the its content by using "b.option", format, you can follow the for more info on contour type:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Thermal Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!