Hi,. I need support in doing a double summation in MATLAB. Thank you.
Mostra commenti meno recenti
Hi,
I need to do the following double summation ∑(i=0,2)∑(j=0,3)〖(2i+3j)〗in a MATLAB program. The answer should be 78. Thank you.
HD
1 Commento
Adam
il 28 Apr 2017
doc for
Risposta accettata
Più risposte (3)
Stephen23
il 28 Apr 2017
>> M = bsxfun(@plus,2*(0:2),3*(0:3).');
>> sum(M(:))
ans = 78
hani daniel
il 28 Apr 2017
0 voti
Star Strider
il 28 Apr 2017
There are likely several ways to code this (I assume this is a coding exercise, since the correct answer is provided).
This is one approach:
i = 0:2;
j = 0:3;
[I,J] = meshgrid(i, j);
f = @(i,j) 2*i + 3*j; % Anonymous Function
fmtx = f(I,J);
Answer = sum(fmtx(:))
I am not documenting it, leaving it for you to understand how it works.
2 Commenti
Star Strider
il 28 Apr 2017
hani daniel’s Answer is copied here:
Hi Star Strider,
Thank you for your answer.
Regards
HD
Star Strider
il 28 Apr 2017
My pleasure!
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!