I need to loop this operation and store them in a matrix

1 次查看(过去 30 天)

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 = 1;
T_A = zeros(p,7);

for x = 2:6

T(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

disp(T)

I need to make the resultant matrix [0 15.9720 27.5000 40.0000 52.5000 60.1400] to be T_i in each loop and store each result in the matrix T_A and I don't now how to do it.

回答(1 个)

Walter Roberson
Walter Roberson 2021-12-2
stainless_steel()
T_A = 1×6
0 15.9720 27.5000 40.0000 52.5000 60.1400
function stainless_steel(~,~,~)
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 = 1;
T_A = zeros(p,6);
for iteration = 1 : p
for x = 2:6
T(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
T_A(iteration, :) = T;
end
T_A
end
  1 个评论
Carlos Puente
Carlos Puente 2021-12-2
编辑:Carlos Puente 2021-12-2
I have my code like this
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
And 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]
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 :(

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by