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

Click For Summary

Discussion Overview

The discussion revolves around computing the sum of the series from J=1 to n of 1/j^2 using various programming tools, particularly focusing on Maple, Matlab, and Excel. Participants explore different methods to achieve this computation, considering aspects of numerical accuracy and the implications of floating-point arithmetic.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant inquires about computing the sum in Maple and seeks guidance on commands or methods to do so.
  • Another suggests using a simple for-loop as a straightforward approach to compute the sum.
  • A participant provides a Matlab code snippet to compute the summation, indicating that it can be done without a loop and showing results that differ slightly based on the order of addition.
  • Concerns are raised about the accuracy of floating-point arithmetic, noting that the order of addition can affect the result due to finite precision.
  • One participant mentions that Excel can also be used for this type of computation, highlighting its flexibility.
  • A later reply expresses gratitude for the alternative method shown in Matlab.
  • Another participant asks how to set single precision with 8 floating digits in Maple, acknowledging the potential differences in results due to numerical precision.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best method to compute the sum, and multiple approaches are presented, indicating a variety of opinions on the most effective or accurate way to perform the calculation.

Contextual Notes

Participants express concerns about the limitations of floating-point arithmetic and its impact on the accuracy of the results, but specific assumptions or dependencies on definitions are not fully explored.

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

  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K