How to expand a summation with different indexes
조회 수: 1 (최근 30일)
이전 댓글 표시
How to expand a summation with different indexes like this?
Any help would be appreciated.
댓글 수: 4
답변 (4개)
Thorsten
2015년 10월 2일
sum(diff(f(1:4)).*n(1:3).*arrayfun(@(x) sum(m(x:end)), 3:5))
댓글 수: 7
Muthu Annamalai
2015년 10월 2일
@Thorsten : nice solution exploiting fact that each sum is independent of the other index, i and j, we may use dot products to compute the inner loop, and repeat it again for index i. I wonder if there is also a way to do it with mesgrid() and matrix products.
Sean de Wolski
2015년 10월 2일
편집: Sean de Wolski
2015년 10월 2일
sum(diff(f(1:4)).*n(1:3).*sum(m(3:5)))
댓글 수: 5
Thorsten
2015년 10월 2일
편집: Thorsten
2015년 10월 2일
Sean, yes, i is 1:3, so the starting index of j is 3:5, so the sum runs for j = 3:5 for i = 1, j = 4:5 for i = 2, and j = 5 for i = 3, i.e., assumes values sum(m(3:5)), sum(m(4:5)) and sum(m(5)) for i=1,2,3. You forgot to sum over the different m(j), as far as I can see.
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!