Hello, i am a beginner in matlab, please if someone can help me to make a summation loop?
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
Lilian Darracq
on 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 Comments
Lilian Darracq
on 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));
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!