How to expand a summation with different indexes
Ältere Kommentare anzeigen
How to expand a summation with different indexes like this?

Any help would be appreciated.
4 Kommentare
John D'Errico
am 2 Okt. 2015
Don't post the same question every 23 minutes.
SooShiant
am 2 Okt. 2015
Stephen23
am 2 Okt. 2015
@SooShiant: Please stop posting the same question again and again.
SooShiant
am 2 Okt. 2015
Antworten (4)
Thorsten
am 2 Okt. 2015
sum(diff(f(1:4)).*n(1:3).*arrayfun(@(x) sum(m(x:end)), 3:5))
7 Kommentare
SooShiant
am 2 Okt. 2015
SooShiant
am 2 Okt. 2015
No. It just means that I gave you the wrong, i.e, numerical answer because I overlooked that by asking to "expand" you asked for a symbolical solution. In the future such mistakes could be avoided if you define your variables as sym and ask for a symbolical solution.
SooShiant
am 2 Okt. 2015
Muthu Annamalai
am 2 Okt. 2015
@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.
SooShiant
am 2 Okt. 2015
Sean de Wolski
am 2 Okt. 2015
Bearbeitet: Sean de Wolski
am 2 Okt. 2015
sum(diff(f(1:4)).*n(1:3).*sum(m(3:5)))
5 Kommentare
SooShiant
am 2 Okt. 2015
Sean de Wolski
am 2 Okt. 2015
Thorsten, i is 1:3 for the example so I could hardwire j.
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.
Sean de Wolski
am 2 Okt. 2015
Ah, so I need to tril() that part.
SooShiant
am 2 Okt. 2015
0 Stimmen
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

