19.7.11

Java Code examples - Bernoulli polynomial function

 /**
   * return nth Bernoulli polynomial of x using Fourier expansion
   * ref: Abramowitz & Stegun 23.1.16 pp 805
   @param n
   @param x
   @return
   */
  public static double BernoulliP (int n, double x)
  {
    // for n>1, 1>=x>=0
    // for n=1, 1>x>0
    
    // for x=0 return the nth Bernoulli number
    if (x==0.0) {
      return BernoulliB(n);
    }
        
    double K = -2*(factorial(n))/StrictMath.pow((2*StrictMath.PI), n);
    
    double S = 0.0;
    for (int k=1; k<100001; k++)
    {
      S += 
        StrictMath.cos((2*StrictMath.PI*k*x)-(.5*StrictMath.PI*n))/
          StrictMath.pow(k, n);
    }
    
    return K*S;
  }

No comments: