function [ v, dvdr ] = lennard_jones ( r )

%*****************************************************************************80
%
%% LENNARD_JONES evaluates the Lennard-Jones potential.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    01 June 2012
%
%  Author:
%
%    John Burkardt.
%
%  Parameters:
%
%    Input, real R, the distance between two particles.
%
%    Output, real V, the value of the potential.
%
%    Output, real DVDR, the derivative of the potential with respect to R.
%
  sigma = 1.0;
  epsilon = 1.0;

  i = find ( r == 0 );
  j = find ( r ~= 0 );

  v(i) = Inf;
  dvdr(i) = -Inf;

  v(j) = 4.0 * epsilon * ( ( sigma ./ r(j) ).^12 - ( sigma ./ r(j) ).^6 );
  dvdr(j) = 4.0 * epsilon * sigma * ( - 12.0 * ( sigma ./ r(j) ).^11 + 6.0 * ( sigma ./ r(j) ).^5 );

  return
end
 
