function [ v, dvdr ] = lennard_jones ( r )

%*****************************************************************************80
%
%% lennard_jones() evaluates the Lennard-Jones potential.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    02 June 2012
%
%  Author:
%
%    John Burkardt.
%
%  Input:
%
%    real R, the distance between two particles.
%
%  Output:
%
%    real V, the value of the potential.
%
%    real DVDR, the derivative of the potential.
%
  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
 
