Skip to content

Commit 48383ae

Browse files
committed
Updating week 5
1 parent 9ef4bfc commit 48383ae

2 files changed

Lines changed: 38 additions & 29 deletions

File tree

CH40208/geometry_optimisation/Lennard_Jones_optimisation.ipynb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"source": [
88
"### Exercise: Geometry Optimisation of a Lennard-Jones Potential\n",
99
"\n",
10-
"The potential energy surface for a pair of &lqduo;Lennard–Jones” is given by\n",
10+
"The potential energy surface for a pair of “Lennard–Jones” is given by\n",
1111
"\n",
1212
"$$U_\\mathrm{LJ} = \\frac{A}{r^{12}} - \\frac{B}{r^6}$$\n",
1313
"\n",
@@ -34,6 +34,14 @@
3434
"\n",
3535
"Investigate how the Newton-Raphson method performs with starting points of $r$ = 3.2 Å, $r$ = 4.4 Å, and $r$ = 6.0 Å."
3636
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": null,
41+
"id": "10ceb78f-ff2f-4f67-ae24-851d7765668d",
42+
"metadata": {},
43+
"outputs": [],
44+
"source": []
3745
}
3846
],
3947
"metadata": {
@@ -52,7 +60,7 @@
5260
"name": "python",
5361
"nbconvert_exporter": "python",
5462
"pygments_lexer": "ipython3",
55-
"version": "3.11.10"
63+
"version": "3.12.3"
5664
}
5765
},
5866
"nbformat": 4,

CH40208/geometry_optimisation/newton_raphson_method.ipynb

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,61 +9,62 @@
99
"\n",
1010
"An alternative method for finding the minimum of a function is the Newton-Raphson Method (also called Newton's Method).\n",
1111
"\n",
12-
"The central idea here is that if we zoom in on any function, then we can approximate the local shape of that function as quadratic, i.e.\n",
12+
"The key insight is that **at a minimum, the first derivative equals zero**: $f^\\prime(x) = 0$. So finding a minimum is equivalent to finding where the derivative vanishes.\n",
13+
"\n",
14+
"The Newton-Raphson method uses the idea that if we zoom in on any function, we can approximate the local shape of that function as quadratic, i.e.\n",
1315
"\n",
1416
"$$f(x) \\approx ax^2 + bx + c$$\n",
1517
"\n",
1618
"over some small range of $x$.\n",
1719
"\n",
18-
"If $f(x)$ has a minimum, then at that point\n",
20+
"If $f(x)$ is approximately quadratic near our current position, then its first derivative is approximately **linear**:\n",
21+
"\n",
22+
"$$f^\\prime(x) \\approx 2ax + b$$\n",
1923
"\n",
20-
"$$f^{\\prime\\prime}(x) = 0$$\n",
24+
"If we know the coefficients $a$ and $b$, we can directly solve for where this linear approximation crosses zero (i.e., where $f^\\prime(x) = 0$):\n",
2125
"\n",
22-
"and, if we know the coefficients $a$ and $b$, then we can directly calculate the value of $x$ that minimises our function.\n",
26+
"$$2ax + b = 0$$\n",
2327
"\n",
24-
"$$f^{\\prime\\prime}(x) = 2ax + b = 0$$\n",
28+
"$$x = \\frac{-b}{2a}$$\n",
2529
"\n",
26-
"$$x = \\frac{-b}{2a}$$\n"
30+
"This gives us our predicted location of the minimum.\n"
2731
]
2832
},
2933
{
3034
"cell_type": "markdown",
3135
"id": "641bab47-12b3-485d-afcb-4d25ad60030f",
3236
"metadata": {},
3337
"source": [
34-
"To find the value of the coefficients $a$ and $b$, we use the property that any function can be expanded as a **Taylor series**\n",
35-
"(see, e.g., Chapter 6 in [Foundations of Science Mathematics](https://bath.primo.exlibrisgroup.com/permalink/44BAT_INST/iac705/alma991004175199902761)).\n",
38+
"To find the coefficients $a$ and $b$ of our local quadratic approximation, we use the property that any smooth function can be expanded as a **Taylor series** (see, e.g., Chapter 6 in [Foundations of Science Mathematics](https://bath.primo.exlibrisgroup.com/permalink/44BAT_INST/iac705/alma991004175199902761)).\n",
3639
"\n",
3740
"If we are at some point $x_0$, then we can approximate our function locally as a polynomial in $(x-x_0)$:\n",
3841
"\n",
3942
"$$f(x) = f(x_0) + f^\\prime(x_0)(x-x_0) + \\frac{1}{2}f^{\\prime\\prime}(x_0)(x-x_0)^2 + \\ldots$$\n",
4043
"\n",
41-
"And, if we remain close to $x_0$, where the higher order terms in $(x-x_0)$ are small, we have the approximation that \n",
44+
"If we remain close to $x_0$, where the higher-order terms in $(x-x_0)$ are small, we can truncate this series after the quadratic term:\n",
4245
"\n",
4346
"$$f(x) \\approx f(x_0) + f^\\prime(x_0)(x-x_0) + \\frac{1}{2}f^{\\prime\\prime}(x_0)(x-x_0)^2$$\n",
4447
"\n",
45-
"i.e., we approximate $f(x)$ as quadratic.\n",
48+
"This is our quadratic approximation. Differentiating this expression with respect to $x$ gives us the approximation for the first derivative:\n",
4649
"\n",
47-
"Differentiating this approximate expression with respect to $x$gives:\n",
50+
"$$f^\\prime(x) \\approx f^\\prime(x_0) + f^{\\prime\\prime}(x_0)(x - x_0)$$\n",
4851
"\n",
49-
"$$f^\\prime(x) = f^\\prime + f^{\\prime\\prime}(x - x_0) = 0$$\n",
52+
"At a minimum, $f^\\prime(x) = 0$, so we can set this expression to zero and solve for $x$:\n",
5053
"\n",
51-
"and setting this to zero allows us to solve for $x$:\n",
54+
"$$f^\\prime(x_0) + f^{\\prime\\prime}(x_0)(x - x_0) = 0$$\n",
5255
"\n",
53-
"$$x = x_0 - \\frac{f^\\prime(x_0)}{f^{\\prime\\prime}(x_0)}$$"
54-
]
55-
},
56-
{
57-
"cell_type": "markdown",
58-
"id": "4c58aee1-7acf-4ac2-a237-a8f77cf57138",
59-
"metadata": {},
60-
"source": [
61-
"In the context of finding the minimum of a potential energy surface, this looks like:\n",
56+
"$$x = x_0 - \\frac{f^\\prime(x_0)}{f^{\\prime\\prime}(x_0)}$$\n",
57+
"\n",
58+
"This is the **Newton-Raphson equation**. Starting from our current position $x_0$, it predicts a new position $x$ that should be closer to the minimum.\n",
59+
"\n",
60+
"In the context of finding the minimum of a potential energy surface, we can rewrite this using our usual notation for energy and bond length:\n",
61+
"\n",
62+
"1. Starting at an initial guess $r_n$, calculate the first and second derivatives of $U(r_n)$ at that point.\n",
63+
"2. Use the Newton-Raphson equation to predict a new position:\n",
64+
"\n",
65+
"$$r_{n+1} = r_n - \\frac{U^\\prime(r_n)}{U^{\\prime\\prime}(r_n)}$$\n",
6266
"\n",
63-
"1. Starting at an initial guess, $r_n$, calculate the first and second derivatives of $U(r_n)$ at that point.\n",
64-
"2. Use the Newton-Raphson equation $r_{n+1} = r_n - U^\\prime(r_n) / U^{\\prime\\prime}(r_n)$ to predict the position of the minimum.\n",
65-
" \n",
66-
"In reality, our potential energy surface is never exactly quadratic (except for the special case of a harmonic potential), so step 2. only gives us an approximate **guess** for the minimum position. We then repeat steps 1. and 2. as an iterative process, until we (hopefully) converge on the energy minimum."
67+
"In reality, our potential energy surface is never exactly quadratic (except for the special case of a harmonic potential), so this equation only gives us an approximate guess for the minimum position. We therefore repeat steps 1 and 2 as an iterative process, recalculating the derivatives at each new position, until we (hopefully) converge on the energy minimum."
6768
]
6869
},
6970
{
@@ -97,7 +98,7 @@
9798
"name": "python",
9899
"nbconvert_exporter": "python",
99100
"pygments_lexer": "ipython3",
100-
"version": "3.11.10"
101+
"version": "3.12.3"
101102
}
102103
},
103104
"nbformat": 4,

0 commit comments

Comments
 (0)