how to write this range in Matlab?
2 次查看(过去 30 天)
显示 更早的评论
how do we write the following type of range in matlab:
∑_jϵN=m_nj
i.e. j lies in N.
Thanks.
2 个评论
Walter Roberson
2016-7-21
It looks to me as if it might be the sum over those j that are elements of (N = m) to (N = n), with the term to be summed being j ?
回答(2 个)
Steven Lord
2016-7-21
Use linear indexing.
% Generate sample data
x = (1:20).^2;
% Generate a set N over which to sum
N = randperm(20, 5)
% Compute the sum over the set N
sumXN = sum(x(N))
% Since the kth element of x is just k^2, check by summing N^2
% Use .^ to perform element-wise squaring
sumN2 = sum(N.^2)
sumXN and sumN2 should be the same.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!