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

In summary, the conversation discusses a computer project involving computing a sum from J=1 to n of 1/j^2 from smallest to largest. Different methods for computing the sum, such as using a for-loop or specific programming languages like Matlab and Maple, are suggested. It is mentioned that due to limited precision on computers, the order of addition can affect the result. The conversation concludes with a suggestion to use Excel for this type of calculation.
  • #1
kholden
6
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
  • #2
Why not just use a simple for-loop?
 
Last edited:
  • #3
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
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
Actually, excel is surprisingly flexible for this kind of stuff.
 
  • #6
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
 
  • #7
D H

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

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

1. What is numerical analysis?

Numerical analysis is a branch of mathematics that deals with developing and using algorithms and methods to solve mathematical problems that cannot be solved analytically. It involves using computers to perform calculations and obtain approximate solutions to mathematical equations.

2. What is the purpose of computing sums from J=1 to n in Maple?

The purpose of computing sums from J=1 to n in Maple is to find the value of a summation or series with a specified number of terms. This is useful in many mathematical applications, such as calculating areas under curves, approximating solutions to differential equations, and evaluating infinite series.

3. How does Maple compute sums from J=1 to n?

Maple uses a variety of numerical methods, such as the trapezoidal rule or Simpson's rule, to approximate the value of a summation. It can also use symbolic methods to find exact solutions in some cases. The specific method used depends on the input and the desired level of accuracy.

4. What are the limitations of computing sums from J=1 to n in Maple?

One limitation of computing sums from J=1 to n in Maple is that it can only provide approximate solutions, which may not be completely accurate. Additionally, the accuracy of the solution depends on the method used and the number of terms in the summation. Maple may also struggle with complex or divergent series.

5. How can I use Maple to compute sums from J=1 to n?

To compute sums from J=1 to n in Maple, you can use the "sum" command, specifying the expression to be summed, the variable and its bounds, and the number of terms. You can also use the "evalf" command to obtain a numerical approximation of the sum. It is important to check the accuracy of the solution and adjust the number of terms or method used if necessary.

Similar threads

Replies
3
Views
2K
Replies
1
Views
1K
Replies
3
Views
3K
Replies
8
Views
2K
Replies
5
Views
2K
Replies
4
Views
1K
Replies
1
Views
4K
Back
Top