Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Numerical Analysis

  1. Sep 13, 2007 #1
    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. jcsd
  3. Sep 13, 2007 #2
    Why not just use a simple for-loop?
     
    Last edited: Sep 14, 2007
  4. Sep 14, 2007 #3

    cks

    User Avatar

    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
     
  5. Sep 14, 2007 #4

    HallsofIvy

    User Avatar
    Staff Emeritus
    Science Advisor

    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)
    }
     
  6. Sep 14, 2007 #5
    Actually, excel is surprisingly flexible for this kind of stuff.
     
  7. Sep 14, 2007 #6

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    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
     
  8. Sep 15, 2007 #7

    cks

    User Avatar

    D H

    Thanks for showing an alternative way
     
  9. Sep 16, 2007 #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??
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Numerical Analysis
  1. Numerical integration (Replies: 2)

  2. Numerical Analysis (Replies: 2)

Loading...