Hello, i am a beginner in matlab, please if someone can help me to make a summation loop?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dawj Alami
le 24 Avr 2017
Commenté : Dawj Alami
le 25 Avr 2017

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.
0 commentaires
Réponse acceptée
Lilian Darracq
le 24 Avr 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 commentaires
Lilian Darracq
le 25 Avr 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));
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
