# Calculation of a double sum

1 Ansicht (letzte 30 Tage)
xenon99942 am 19 Jul. 2018
Hey all!
i want to calculate the double sum over w_ij * v_((2+k*3)+i,(2+l*3)+j). The indices for i should run from -1 to 1 (so -1,0,1), same for j. The indices for k are from 0:893 and for l from 0:356. And w should be -8 if i=j=0, otherwhise it is w=1. i Tried:
for i = -1:1
for j = -1:1
if i == 0 & j==0
w = -8
else
w = 1
end
for k = 0:893
for l = 0:356
sum(w*v((2+k*3)+i,(2+l*3))+j)
end
end
end
end
% code
end
But the results were not as expected. Can you help me? Thanks!
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Dimitris Kalogiros am 19 Jul. 2018
mySum=0;
for i = -1:1
for j = -1:1
if i == 0 & j==0
w = -8;
else
w = 1;
end
for k = 0:893
for l = 0:356
mySum=mySum+( w*v((2+k*3)+i,(2+l*3))+j );
end
end
end
end
disp(['mySum = ' num2str(mySum)]);
##### 0 Kommentare-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by