I'm trying to draw isothermal lines and heat flow lines, I've done some research and was able to reach to this point:
clear ,clc
T1=10;
Lx=1;
Ly=1;
Nx=5;
Ny=5;
Nz=5;
Lz=1;
T2=150;
%input('input temperature at y=Ly in deg. C: ')
dx=Lx/Nx;
dy=Ly/Ny;
x=[0:dx:1];
y=[0:dy:1];
theta = zeros(Nx + 1, Ny + 1);
theta(:,Ny+1) = 1;
Nc=12;
for j = 2:Ny
for i = 2:Nx
for n=1:1:199
Theta=(2/pi).*x;
x=((((-1)^(n+1))+1/n).*sin(n.*pi.*x/Lx).* ...
(sinh(n.*pi.*y/Lx)/sinh(n.*pi.*Ly/Lx)));
T=(Theta*(T2-T1))+T1;
end
end
end
for j = Ny+1:-1:1
fprintf('%7.1f', T(:,j))
fprintf('\n')
end
dT = (T2-T1)/Nc;
v = T1:dT:T2;
colormap(jet)
contourf(x, y, T, v)
colorbar
Tmax = max(T1,T2)
Tmin = min(T1,T2)
caxis ([Tmin, Tmax])
axis equal tight
title('Contour Plot of Temperature in deg. C')
xlabel('x (m)')
ylabel('y (m)')
but I'm getting the following error when I try to run it:
76.6
10.0
10.0
10.0
10.0
10.0
Error using contourf (line 69)
Z must be size 2x2 or greater.
Error in Isotherms (line 35)
contourf(x, y, T, v)
any help will be appreciated, thanks in advance.
You've got a bunch of issues. The ones that I see are:
First, at the top, you define your
xasx=[0:dx:1];, but then in your triple-loop, you overwrite it asx=((((-1)^(n+1))+1/n).*sin(n.*pi.*x/Lx).* .... Did you really mean to overwrite it? Or, should the line in the triple-loop be assigned to a new variable?Second, in your triple-loop, your loop over
jandidon't seem to do anything. It looks like you want to loop over each element inxandy, but you're not doing that. Either these loops are unnecessary, or you need to use them to index into yourxandyvariables that you are using in the calculations at the heart of your loop.Third, assuming that your triple-loop is necessary, I see that you are computing
Tfor each step throughiandj, but you are not saving theTvalue in any way...Tgets overwritten with every loop. I think that you probably want to save theTvalue via something like `T(i,j)=(Theta*(T2-T1))+T1;".Finally, when you call your
contourcommand, the size ofT(ie, the number of rows and columns) must be compatible with thexandyvectors that you are also giving tocontour. Specifically, thelength(x)must equal the number of rows ofTandlength(y)must equal the number of columns ofT(or vice versa, if you simply use transpose ofT).Given that your existing
forloops go2:N, I don't think that you're going to end up withTof the right size. So, you might need to do something like `contour(x(2:end),y(2:end),T,v);'