-3

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.

Robert Karl
  • 7,598
  • 6
  • 38
  • 61
Mohamed Maher
  • 45
  • 1
  • 3
  • 8

1 Answers1

0

You've got a bunch of issues. The ones that I see are:

First, at the top, you define your x as x=[0:dx:1];, but then in your triple-loop, you overwrite it as x=((((-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 j and i don't seem to do anything. It looks like you want to loop over each element in x and y, but you're not doing that. Either these loops are unnecessary, or you need to use them to index into your x and y variables 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 T for each step through i and j, but you are not saving the T value in any way...T gets overwritten with every loop. I think that you probably want to save the T value via something like `T(i,j)=(Theta*(T2-T1))+T1;".

Finally, when you call your contour command, the size of T (ie, the number of rows and columns) must be compatible with the x and y vectors that you are also giving to contour. Specifically, the length(x) must equal the number of rows of T and length(y) must equal the number of columns of T (or vice versa, if you simply use transpose of T).

Given that your existing for loops go 2:N, I don't think that you're going to end up with T of the right size. So, you might need to do something like `contour(x(2:end),y(2:end),T,v);'

chipaudette
  • 1,655
  • 10
  • 13