Reputation: 11
function stainless_steel(~,~,~)
clear,clc
T_i = [0 0 12.5 25 37.5 50 0];
k = 0.0162;
cp = 0.5;
rho = 8000;
dt = 3;
dx = 0.0125;
t = 120;
q = 20000;
Fo = (k*dt)/(((dx)^2)*rho*cp);
e_gen = q*(dt)/(rho*cp);
n = t/dt;
p = n;
T = zeros(n,7);
for iteration = 1:p
for x = 2:6
T(iteration,x) = [Fo*(T_i(1,x+1)+273.15 + T_i(1,x-1)+273.15) + (T_i(1,x)+273.15)*(1-2*Fo) + e_gen - 273.15];
end
end
T_i = T;
disp(T)
end
I'm getting this as a result:
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
0 15.9720 27.5000 40.0000 52.5000 60.1400 0
But what I need is the matrix T_i to change each time. For example, if T_i at the beginning was
[0 0 12.5 25 37.5 50 0]
I need my second T_i to be
[ 0 15.9720 27.5000 40.0000 52.5000 60.1400 0]
which is the result I got from the original T_i
And my third T_i to be whatever result I get from the second T_i being T_i and so on for 40 iterations. But I don't know how to achieve that :(
Upvotes: 1
Views: 42
Reputation: 23
You could solve it by using the the following lines:
T_i = zeros(n,7);
T_i(1,:) = [0 0 12.5 25 37.5 50 0];
for iteration = 1:p-1
for x = 2:6
T_i(iteration+1,x) = [Fo*(T_i(iteration,x+1)+273.15 + T_i(iteration,x-1)+273.15) + (T_i(iteration,x)+273.15)*(1-2*Fo) + e_gen - 273.15];
end
end
This makes sure that for every row you go down in your matrix, the information of the row above is used as input. I defined it as T_i but you might want to change that as it suggests that it is the initial value. The actual initial value in my example is T_i(1,:)
Upvotes: 0