Code covered by the BSD License  

Highlights from
Generation of Random Variates

image thumbnail

Generation of Random Variates

by

James Huntley

 

generates random variates from over 870 univariate distributions

lerch2(a, b, c)
% LERCH estimates the Lerch transcendent function.
%
%
%  Definition:
%
%    The Lerch transcendent function is defined as:
%
%      LERCH ( A, B, C ) = Sum ( 0 <= K < Infinity ) A**K / ( C + K )**B
%
%    excluding any term with ( C + K ) = 0.
%
%   NOTE: 0 < |A| < 1 !!!
%
%  Reference:
%
%    Eric Weisstein, editor,
%    CRC Concise Encylopedia of Mathematics,
%    CRC Press, 1998.
%
%  Modified:
%
%    17 December 1999
%
%  Author:
%
%    John Burkardt
%
%  Thanks:
%
%    Oscar van Vlijmen
%
%  Translated/Modified: 
%
%    Jim Huntley, 03/10/04
%
%  Parameters:
%
%    Input, real A, B, C, the parameters of the function. 
%
%    Output, real LERCH, an approximation to the Lerch transcendent function.
%
  
function [lrch] = lerch2(a, b, c)
  sum = 0;
  k = 0;
  a_k = 1;
  lrch = 0;
  eps0 = 1e-8;

  while(lrch == 0)

    sum_old = sum;

    if (c + k == 0) 
      k = k + 1;
      a_k = a_k * a; 
    else    
        sum = sum + (a_k) / (c + k)^b;
        dif = sum - sum_old;
        if (abs(dif) <= eps0)
            break
        end

        k = k + 1;
        a_k = a_k * a;
    end

  end

  lrch = sum;

  return

Contact us