<jupyter_start><jupyter_text>ExerciseThis time we need the first and second derivatives.<jupyter_code>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<jupyter_output><empty_output><jupyter_text>We when implement Newtons method, which does not need hyperparameters.<jupyter_code>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)<jupyter_output><empty_output><jupyter_text>It is easier to show the convergence with a plot.<jupyter_code>import matplotlib.pyplot as plt

plt.plot(range(31), r_list, 'o--')
plt.xlabel('Iteration')
plt.ylabel('r')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1279887482419128, 'fraction_numerical': 0.02109704641350211, 'mean_word_length': 2.8986301369863012, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '373819', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 539, 'n_tokens_neox': 492, 'n_words': 141, 'path': 'CH40208/comp_chem_methods/newtons_exercises.ipynb', 'repo_name': 'pythoninchemistry/ch40208', 'size': '1422'}