function [F,ll] = logn_cdf(x,params)
% [F,ll] = logn_cdf(x, [ median , cv ])
% return CDF of lognormal distribution
%    x     - set of values at which the CDF is computed
%    [medX, covX] - a vector containing the median and coefficient of variation
%
%    If X is a lognormal random variable, then the log of X is normally 
%    distributed with a mean of log(M), and a variance of  log(1+C^) 
%
%    Reference: http://en.wikipedia.org/wiki/Log-normal_distribution


  medX = params(1);		% median of X
  covX = params(2);		% coefficient of variation of X

  idx = find(x<=0);
  x(idx) = 0.01;

  Vlnx = log(1 + covX^2);		% variance of log X

  F = ( 1 + erf( (log(x) - log(medX))./sqrt(2*Vlnx) ) )/2;

% the log likelihood of the sample x from the a lognormal distribution with 
% the given median and coefficient of variation 
  if nargout == 2,  
    ll = sum(log(logn_pdf(x,medX,covX))) 
  end

% -------------------------------------------------------------------- logn_cdf 
% HP Gavin 2011-03-30, 2021-04-26 
