Numerical Analysis: Computing Sums from J=1 to n in Maple

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
7 replies · 4K views
kholden
Messages
6
Reaction score
0
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??
 
Physics news on Phys.org
Why not just use a simple for-loop?
 
Last edited:
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
 
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)
}
 
Actually, excel is surprisingly flexible for this kind of stuff.
 
D H

Thanks for showing an alternative way
 
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??