How do I perform a for-loop with 2 variables

I am trying to simulate the heating of a cube. Energy coming only from the top Surface. Seeing the cube as a single mass-point wasnt a Problem, but now I have to "cut " it into 10/20/30 layers. How can I simulate the heating over time, while taking into account that the 10 layers are transferring the heat from each layer. I dont want the 2nd variabel to be time-dependant.

3 Comments

I think i got the idea. What I am trying (and not managing) to do now is solving the following term with C1 and C2 as a constant value.
n=Number of timesteps
tMax = 12hours
h =hight of the block
s= number of layers
dt=tMax/n
dx=h/s
for i=2:n
for m=2:s %Want to run to the last layer,
I would define T(i,s+1)= T(i,s) since the bottom of the block is isolated
T(1,m)=290 %Starting Temp [K]
T(i,1)= C2*exp(-t(i)*10^(-4.1))+T(i-1,1);
T(i,m)=(T(i,m+1)+T(i,m-1)+C1*T(i-1,m))/(C1+2);
end
end
Thats what I have in mind but cant get to work. M is the number of the current layer and it should write every layer's Temperatur at any point in time into my matrix. In the end i want to sum up the layers at any instance of i and divide them by the number of layers (s) to have an average temperature of the block itself.
I need help to make this work by creating proper matrixes. I am not too sure about the way I loop either. In general working with equations that need 2 variables and therefore matrixes arent something I am used too, so i would be so thankful for any help.
Now i coded this: (T_0 is the starting temp,) It seems to do what it shoudl for the first 10 intervals:
</matlabcentral/answers/uploaded_files/138933/test.JPG> after the 10 intervals it starts doign wierd things
dt=tTOT/n;
dx=h/l;
C1=(roh*c*dx^2)/(dt*lam);
C2=(q_s*A*dt)/(V*roh*c);
T=T_0*ones(l,n);
for i=2:n
for m=2:l
T(i,1)= C2*exp(-(dt*(i-1))*10^(-4.1))+T(i-1,1);
T(i,m)=(T(i,m+1)+T(i,m-1)+C1*T(i-1,m))/(C1+2);
end
end

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Asked:

on 30 Oct 2018

Edited:

on 31 Oct 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!