# Numerical Analysis

1. Sep 13, 2007

### kholden

This is for a computer project and the questions asks to compute a sum from J=1 to n of 1/j^2 from smallest to largest... i.e. (1/n^2+ 1/(n-1)^2+...1/9+1/4+1) for n=10, n=100, n=1000, n=10000, and n=100000

Is there i way i can do this in my calculator? or is there i command i can use in maple??

2. Sep 13, 2007

### bomba923

Why not just use a simple for-loop?

Last edited: Sep 14, 2007
3. Sep 14, 2007

### cks

Using Matlab language, I don't understand your second part of the question that is the question after i.e. so I assume you want us to help you on computing the summation of 1/j^2

sum=0;
for j=1:n
sum=sum+1/(j)^2
end

4. Sep 14, 2007

### HallsofIvy

Staff Emeritus
obviously, since addition is commutative, ideally, such a calculation should give the same thing whether added "smallest numbers first" or "largest numbers first". However, since a computer can only keep a finite number of digits for a floating point number, the actual result on a computer can be different. I suspect this exercise was to show that.

I don't know what calculator you are using and I am no expert with MAPLE but generally you want something like this:

Let S= 0 (we're going to keep a running sum)
Loop for k= n down to 1
{
S= S+ 1/k^2 (the 1/k^2 is where you may lose accuracy)
}

5. Sep 14, 2007

### genneth

Actually, excel is surprisingly flexible for this kind of stuff.

6. Sep 14, 2007

### Staff: Mentor

This can be done without a loop in Matlab.
Code (Text):
>> N = 100000;
>> a = N:-1:1;
>> sum(1./a.^2)
ans =
1.64492406689823
Reversing the order gives a slightly different answer:
Code (Text):
>> a = 1:N;
>> sum(1./a.^2)
ans =
1.64492406689824

7. Sep 15, 2007

### cks

D H

Thanks for showing an alternative way

8. Sep 16, 2007

### kholden

How would i give the command in maple to have single precision 8 floating digits. Though addition is commutative the numbers should differ some what because of this. How would i give the summation command to find the answers??