Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Having trouble evaluating this sum

DataWhoreDataWhore Posts: 2Member
I need help evaluating the following sum:
[img=http://img228.imageshack.us/img228/9540/sumln2.gif]

I tried writing a C++ program to help evaluate it, but because the factorials & exponents get so large the standard libraries cannot handle it nor any calculator I have. So I was hoping to get some advice on here. What would you recommend doing in order to solve this problem?

(I am in the process of getting MATLAB, never used it, and if there is no simpler solution I was planning on learning to use it to perhaps help solve it.)

Thanks...

Comments

  • zibadianzibadian Posts: 6,349Member
    : I need help evaluating the following sum:
    : [img=http://img228.imageshack.us/img228/9540/sumln2.gif]
    :
    : I tried writing a C++ program to help evaluate it, but because the
    : factorials & exponents get so large the standard libraries cannot
    : handle it nor any calculator I have. So I was hoping to get some
    : advice on here. What would you recommend doing in order to solve
    : this problem?
    :
    : (I am in the process of getting MATLAB, never used it, and if there
    : is no simpler solution I was planning on learning to use it to
    : perhaps help solve it.)
    :
    : Thanks...
    :
    Don't try to calculate 365! or (367-n)! or (1/365)^n; those individual values grow to fast outside the range of nearly all standard libraries.
    Instead use maths to reduce those values. Write the first couple of n out. This will give you the following (I've left out the n*(n-1) for readability):
    For n = 2:
    [code]
    365!/(365!) * (1/365)^2 = 1 * (1/365)^2
    [/code]
    For n = 3:
    [code]
    365!/(364!) * (1/365)^3 = 365 * (1/365)^3 = (365 / 365) * (1/365)^2
    [/code]
    For n = 4:
    [code]
    365!/(363!) * (1/365)^4 = 364*365 * (1/365)^4 =
    (364 / 365) * (365 / 365) * (1/365)^2
    [/code]
    For n = 5:
    [code]
    365!/(362!) * (1/365)^5 = 363*364*365 * (1/365)^5 =
    (363 / 365) * (364 / 365) * (365 / 365) * (1/365)^2
    [/code]
    As you can see the calculation can be reduced to a loop, which calculates (367-i)/365 and multiplies the results together. Finally the result of this loop can be multiplied by (1/365)^2 and n*(n-1). The result of each of these multiplication doesn't get very small or very large. The result may be quite small, but should be within limits of a standard library.
  • DataWhoreDataWhore Posts: 2Member
    You are absolutely right, thank you!
Sign In or Register to comment.