Is it possible to make the program faster?
Show older comments
My problem is that i have a program with many operations that runs for more than 12 hours and i would like to ask if there is any possibility to make it run faster. I am using two for loops where the first one runs the timesteps for one year in steps of 2.5s. So there we already have 12.614.400 iterations and within this for loop we have another for loop that runs over the number of layers of a watertank. I would like to know if i could somehow exchange my for loops to make the program run faster.
clear all
roh_w = 983.2;
cp_w = 4183;
lambda_w = 0.6544;
dt = 2.5;
m_strom = 1;
r = 0.5;
h = 2.5;
Tankschichten = 60;
Zeitschritte = 1440;
T_Start = 80;
T_ein = 50;
A_Tank = pi*r*r;
h_Schicht = h/Tankschichten;
v_w = m_strom/(roh_w*A_Tank);
CFL = (v_w*dt)/h_Schicht;
Fo = (lambda_w*dt)/(roh_w*cp_w*h_Schicht*h_Schicht);
T = zeros(Tankschichten,1);
for x = 1 : Zeitschritte
T_old = T;
if x == 1
for y = 1 : Tankschichten
T(y) = 80;
end
else
for y = 1 : Tankschichten
if y == 1
T(y) = (Fo + CFL)*T_ein + (1 - 2*Fo - CFL)*T_old(y) + Fo*T_old(y+1);
elseif y == Tankschichten
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
end
T_store(:,x) = T;
end
figure
plot(T_store(50,:))
hold on
ylabel("Temperatur [°C]")
xlabel("Timestep")
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!