Calculation of a double sum
2 views (last 30 days)
Show older comments
xenon99942
on 19 Jul 2018
Answered: Dimitris Kalogiros
on 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 Comments
Accepted Answer
Dimitris Kalogiros
on 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 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!