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

AI Thread Summary
The discussion revolves around computing the sum of the series 1/j^2 from j=1 to n for various values of n (10, 100, 1000, 10000, and 100000). Participants explore methods for performing this calculation using different tools, including calculators, Maple, and Matlab. A simple for-loop is suggested as a straightforward approach in Matlab, with code provided to compute the sum. It is noted that while addition is commutative, the order of operations can affect results due to floating-point precision limitations in computers. Examples show that summing from largest to smallest yields slightly different results compared to summing from smallest to largest, highlighting potential accuracy issues. Additionally, there is a request for guidance on using Maple to achieve single precision with eight floating digits for the summation.
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.
 
This can be done without a loop in Matlab.
Code:
>> N = 100000;
>> a = N:-1:1;     
>> sum(1./a.^2)
ans =
   1.64492406689823
Reversing the order gives a slightly different answer:
Code:
>> a = 1:N;     
>> sum(1./a.^2)
ans =
   1.64492406689824
 
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??
 

Similar threads

Back
Top