Is it possible to create a Simulink model from my code?
이전 댓글 표시
I am new to Matlab and Simulink and i just created some code in Matlab and i tried to do the same thing in Simulink but i was not able to complete it. I was not able to reproduce the system by only using Simulink blocks because i did not find any possibility to get access to the data for the temperatures in previous timesteps. I also tried to use the Simulink function block but it did not work as well because i was not able to get an vector as output.
clear all
% Constants
roh_w = 983.2;
cp_w = 4183;
lambda_w = 0.6544;
dt = 2.5;
m_strom = 1;
r = 0.5;
h = 2.5;
Tanklayers = 60;
Timesteps = 1440;
T_Start = 80;
T_in = 50;
A_Tank = pi*r^2;
h_layer = h/Tanklayers;
v_w = m_strom/(roh_w*A_Tank);
CFL = (v_w*dt)/h_layer;
Fo = (lambda_w*dt)/(roh_w*cp_w*h_layer^2);
T = zeros(Tanklayers,1);
T_store = zeros(Tanklayers,Timesteps);
% Calculating the temperature in the tank
for x = 1 : Timesteps
T_old = T;
if x == 1
for y = 1 : Tanklayers
T(y) = 80;
end
else
for y = 1 : Tanklayers
if y == 1
T(y) = (Fo + CFL)*T_in + (1 - 2*Fo - CFL)*T_old(y) + Fo*T_old(y+1);
elseif y == Tanklayers
T(y) = (Fo + CFL)*T_old(y-1) + (1 - 2*Fo - CFL)*T_old(y) + Fo*T_old(y);
else
T(y) = (Fo + CFL)*T_old(y-1) + (1 - 2*Fo - CFL)*T_old(y) + Fo*T_old(y+1);
end
end
T_store(:,x) = T;
end
end
figure
plot(T_store(50,:))
hold on
ylabel("Temperatur [°C]")
xlabel("Timestep")
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Modeling에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!