function [ MySum ] = spiral_diag_sum( n )
MySum=1; if n==1 return end for i=3:2:n mult=0; j=0; while j <= (i-3)/2 mult=mult+j; j=j+1; end MySum=MySum+(4*(i+mult*8)+6*(i-1)); end
end
this for some reason works but i dont undestand how. What does the while loop do? And how do you figure out the MySum part?
Best Answer