Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
Summation issue using loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I am trying to implement this summation in matlab but i do not know how ?
thank u
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/243279/image.png)
1 Kommentar
Antworten (2)
Robert U
am 20 Okt. 2019
Hi Ali aaa,
in your code parts are missing. Without knowing any constraints about the variables, I suggest the following solution:
- Define a (local) function to solve the summation formula
- check input validity
- Try to vectorize the calculation
function [Em] = sum_mNi(x,m,N)
validateattributes(x,{'numeric'},{'vector','nonempty'});
validateattributes(m,{'numeric'},{'scalar','nonempty'});
validateattributes(N,{'numeric'},{'scalar','nonempty'});
Em = 1/N * sum(cell2mat(arrayfun(@(ind) x.^2 .* (m*N + ind),0:N-1,'UniformOutput',false)'),1);
end
The solution might be wrong, depending on the input value types.
Kind regards,
Robert
0 Kommentare
Diese Frage ist geschlossen.
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!