Exercise#

This time we need the first and second derivatives.

def first_derivative(r, A, B):
    """
    The first derivative of the Lennard-Jones potential model. 
    
    Args:
        r (float): Atom-atom distance (Å).
        A (float): Interaction parameter (eVÅ^12).
        B (float): Interaction parameter (eVÅ^6).
        
    Returns:
        (float): Potential energy.
    """
    return -12. * A / r ** 13 + 6 * B / r ** 7

def second_derivative(r, A, B):
    """
    The second derivative of the Lennard-Jones potential model. 
    
    Args:
        r (float): Atom-atom distance (Å).
        A (float): Interaction parameter (eVÅ^12).
        B (float): Interaction parameter (eVÅ^6).
        
    Returns:
        (float): Potential energy.
    """
    return 156. * A / r ** 14 - 42 * B / r ** 8

We when implement Newtons method, which does not need hyperparameters.

A = 1e5
B = 40

r = 4.4
r_list = [r]
for i in range(30):
    E_dash = first_derivative(r, A, B)
    E_ddash = second_derivative(r, A, B)
    r = r - E_dash / E_ddash
    r_list.append(r)

It is easier to show the convergence with a plot.

import matplotlib.pyplot as plt

plt.plot(range(31), r_list, 'o--')
plt.xlabel('Iteration')
plt.ylabel('r')
plt.show()
../_images/13f0e0aae3309a5dbc95d68d1fe8bcc606af15319c098cab8d6a4e56150aec62.png

To consider the cause of the result where the starting value is 6.0 Å, watch the following LOIL (Bath moodle access required).