2

I am trying to write a piece of code in java that needs to calculate the sum of values in following manner for the range [-∞, +∞]

K= +∞

∑ [ f( (2K+1)*x ) - f( (2K-1)*x ) ]

K= -∞

There are two confusions that I am facing with the calculation to produce a computationally feasible and efficient solution:

  1. what value must be assumed for ∞ to approximate the calculation as above?

  2. what minimum value must be used to increment K within loop, assuming that K holds fractional values too.

A. Sinha
  • 2,666
  • 3
  • 26
  • 45
  • 2
    You know that this is a telescoping sum and actually the difference of the (separate) limits of `f(2m+1)` and `f(-2n-1)`? – Lutz Lehmann Nov 05 '15 at 12:38
  • Can you tell us what `f` is? –  Nov 05 '15 at 12:38
  • @RC f () is Cumulative Distribution Function – A. Sinha Nov 05 '15 at 12:42
  • Are you sure K can have fractional values? The index of a sum is supposed to be an integer, otherwise this would be an integral. – RealSkeptic Nov 05 '15 at 13:00
  • @RealSkeptic absolutely sir – A. Sinha Nov 05 '15 at 13:04
  • @LutzL Sir but as we know that value of infinity can't be defined, so what value can be used to approximate ∞ in a programming language like java. – A. Sinha Nov 05 '15 at 13:58
  • Please reformulate your question to give more details about the broader situation. What problem led you to evaluate that sum. Where do you get the idea that the summation index `K` might assume rational values. -- If `f` is really a CDF then the answer is `1`. – Lutz Lehmann Nov 05 '15 at 14:02

1 Answers1

0

First of all, in order to get an approximation you need the value to decrease dramatically. For example, -1/x. If x increases much the answer will be near zero.

  1. What value must be assumed for to approximate the calculation as above?
for ( float k = 0 ; ; k++ ) 
{
    sum += (((2 * ( k) + 1) * x) - ((2 * ( k) - 1) * x));   //adding from 1 to infinity
    sum += (((2 * (-k) + 1) * x) - ((2 * (-k) - 1) * x));    //adding from -1 to infinity
}

but this will result in an infinite loop. You can replace x with 1/x and increase x each time in the loop. The code becomes

if ( (sum - lastsum) < 0.001 )
{
    break;
}
    lastsum = sum;
}
  1. What minimum value must be used to increment K within [the] loop, assuming that K holds fractional values too?

This is according to the type of K. If it is double, it could have up to 15 decimal places.

In addition, in the summation, you should move by one, not a fraction. See https://upload.wikimedia.org/math/d/f/2/df26e1cf51b67fbedd01ce9c68cbbef5.png https://en.wikipedia.org/wiki/Summation

Teepeemm
  • 4,331
  • 5
  • 35
  • 58
Amro Walid
  • 16
  • 1