Hello, i am a beginner in matlab, please if someone can help me to make a summation loop?

1 Ansicht (letzte 30 Tage)
Knowing, that I have already calculated the values of the temperature in each point of space (1 to N) and as a function of time. So I need to calculate at each step of time the energy stored in my system in all the space points ..! The other parameters are constants. Help me and thank you in advance.

Akzeptierte Antwort

Lilian Darracq
Lilian Darracq am 24 Apr. 2017
Lets say you have stored your values into two differents vectors of length N :
theta_f = ...
theta_s = ...
Then you just have to type :
Energy = AH*deltaX*(epsilon_p*C_p_f*theta_f + (1-epsilon)*ro_s*_Cp_s*theta_s)*(T_h - T_amb);
% Calculates the energy at each step and stores it into a vector
Total_Energy = sum(Energy,1)
% Sums the energy vector to get the total energy
  5 Kommentare
Lilian Darracq
Lilian Darracq am 25 Apr. 2017
If i understand this sum well, everything is constant except theta, which is a matrix, with n being columns index (space), and j being rows index (time).
The MATLAB function sum mainly takes two arguments : the vector/matrix you want to used, and the direction alongside which you want to sum.
Here you want to sum on columns (n) then rows (j). To do so, type this :
theta = ... % Matrix with tau rows and N columns
Energy_time = sum(U_pert*P*delta_X*theta*(Th-Tamb),2);
Energy_total = sum(Energy_time,1);
% Or
Energy_total = sum(sum(U_pert*P*delta_X*theta*(Th-Tamb),2), 1);
% Or even faster
Energy_total = sum(sum(U_pert*P*delta_X*theta*(Th-Tamb));
Dawj Alami
Dawj Alami am 25 Apr. 2017
Yes that's right, the program is working properly. Thank you so much for your help ^__^

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by