Multiply by 4 after summing the terms not while you're summing the terms. Otherwise the first term will be multiplied by 4 many times. Also you don't need a nested pair of loops; you're summing over k (with an upper limit of m = 25) so you don't need to loop over m. If you wanted to show the effect of increasing the upper limit of summation, you could make a vector in which you store the current result for each value of k.
Finally, I'd avoid calling your variable sum. While that variable exists you will not be able to call this somewhat useful function.
Best Answer