"Chris " <ridered300tr@hotmail.com> wrote in message <i6ur20$2lt$1@fred.mathworks.com>...
> I want to sum the expression forwards (and backwards):
>
> n
> summation : 1/(i^4)
> i=1
>
> right now I have:
>
> function [forward backward] = summ(k)
> format long %shows 7 digits after decimal
> sum = 0; % start sum at zero
> sum2 = 0;
> for h = 1:k
> forward = sum + 1/(k^4); %forward summation
> end
>
> for h = 1:k
> backward = sum2 + 1/(k^4); %backward summation
> end
> end
>
> I know the forward sum with 38 terms should be 1.082318 but my result comes out to be 4.795850246698537e007 and I cannot figure out why.
> Is my summation wrong?
Hi
I guess this code is being used to check the effect of changing k, the total number of terms.
your first loop says
for h = 1:k
forward = sum + 1/(k^4); %forward summation
end
but where it says k^4, you should have h^4
your second loop has the same problem. it also has another problem  if you want to go backwards then you need to use a FORloop from k to 1 with increments of 1. read the help to find out how.
Ross
