diff --git a/06_roots-1/06_roots-1.ipynb b/06_roots-1/06_roots-1.ipynb
index e95edef..1e1c23e 100644
--- a/06_roots-1/06_roots-1.ipynb
+++ b/06_roots-1/06_roots-1.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 2,
"metadata": {
"collapsed": true,
"scrolled": true,
@@ -53,7 +53,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 1,
"metadata": {
"collapsed": false,
"scrolled": true,
@@ -64,155 +64,9 @@
"outputs": [
{
"data": {
- "image/svg+xml": [
- ""
- ],
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAGkCAIAAACgjIjwAAAJNmlDQ1BkZWZhdWx0X3JnYi5pY2MA\nAHiclZFnUJSHFobP933bCwvssnRYepMqZQHpvUmvogJL7yxLEbEhYgQiiog0RZCggAGjUiRWRLEQ\nFBSxoFkkCCgxGEVUUPLDOxPn3vHHfX49884755yZA0ARBQBARQFSUgV8Pxd7TkhoGAe+IZKXmW7n\n4+MJ3+X9KCAAAPdWfb/zXSjRMZk8AFgGgHxeOl8AgOQCgGaOIF0AgBwFAFZUUroAADkLACx+SGgY\nAHIDAFhxX30cAFhRX30eAFj8AD8HABQHQKLFfeNR3/h/9gIAKNvxBQmxMbkc/7RYQU4kP4aT6edi\nz3FzcOD48NNiE5Jjvjn4/yp/B0FMrgAAwCEtfRM/IS5ewPmfoUYGhobw7y/e+gICAAh78L//AwDf\n9NIaAbgLANi+f7OoaoDuXQBSj//NVI8CMAoBuu7wsvjZXzMcAAAeKMAAFkiDAqiAJuiCEZiBJdiC\nE7iDNwRAKGwAHsRDCvAhB/JhBxRBCeyDg1AD9dAELdAOp6EbzsMVuA634S6MwhMQwhS8gnl4D0sI\nghAROsJEpBFFRA3RQYwQLmKNOCGeiB8SikQgcUgqkoXkIzuREqQcqUEakBbkF+QccgW5iQwjj5AJ\nZBb5G/mEYigNZaHyqDqqj3JRO9QDDUDX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AiCBIAEQQJAAiCBIAEQQJgAiC\nBEAEQQIggiABEEGQAIggSABEECQAIggSABEECYAIggRABEECIIIgARBBkACIIEgARBAkACIIEgAR\n3o0+Yl3X+wtVVc1ms9HHB+AsjRykpmmGDtV1LUgAPNHIS3Zd1w0Rms1m2+123PEBOFcjB2k6nQ6X\nq6rqum7c8QE4Vw5qAOB5+r4/xbCCBMDzFEVximEFCYAIIwdpt9sNl7fbraPsAHiikYM0m82GAxm6\nrquqatzxAThXI5+HNJ/P67reH+2tRgA83fif1LBcLkcfE4Cz56AGACIIEgARBAmACIIEQARBAiCC\nIAEQQZAAiCBIAEQQJAAiCBIAEQQJgAiCBEAEQQIggiABEEGQAIggSABEECQAIggSABEECYAIggRA\nBEECIIIgARBBkACIIEgARBAkACIIEgARBAmACIIEQARBAiCCIAEQQZAAiCBIAEQQJAAiCBIAEQQJ\ngAiCBEAEQQIggiABEEGQAIggSABEECQAIggSABEECYAIggRABEECIIIgARBBkACIIEgARBAkACII\nEgARxg/Sdru9vLwcfVgAztuYQer7/uLiou/7EccE4I14N+JYRVFsNpvJZFLX9YjDAvAW2IcEQARB\nAiDC85bs+r5vmub+z5fL5UjzASDd7e3tKYZ9XpCKotAegDfu/fv3pxjWkh0AEQQJgAhjHvY97GHq\num5/5HdRFPP5fMS7AOBcjXwekj1MAPw3luwAiCBIAEQQJAAiCBIAEQQJgAiCBEAEQQIggiABEEGQ\nAIggSABEECQAIggSABEECYAIggRABEECIIIgARBBkACIIEgARBAkACIIEgARBAmACIIEQARBAiCC\nIAEQQZAAiCBIAEQQJAAiCBIAEQQJgAiCBEAEQQIggiABEEGQAIggSABEECQAIggSABEECYAIggRA\nBEECIIIgARBBkACIIEgARBAkACIIEgARBAmACIIEQARBAiCCIAEQQZAAiCBIAEQQJAAivBt3uK7r\nmqaZTqeTyaQsy7Isxx0fgHM1ZpB2u91qtdpsNvurq9WqKIqiKEa8CwDO1ZhLdn3fz+fz4episWia\nZsTxAThjY24hzWazw6tt2+7X7gDgX428D2lwtHwHwNm4vb09xbDPC1Lf9w+uwi2Xy8Oru92uruvN\nZmMLCeD8vH///iTj3o3t+vq6LMvr6+sn3v4kjwqAk/n48ePo7bi7uxv/sO+Li4vNZuPgOgCeZcyj\n7Lqu26/UDUc3bLfbEccH4IyNuYVU1/VsNttut4cdqqpqxLsA4FyNGaSrq6sRRwPgTfFZdgBEECQA\nIggSABEECYAIggRABEECIIIgARBBkACIIEgARBAkACIIEgARBAmACIIEQARBAiCCIAEQQZAAiCBI\nAEQQJAAiCBIAEQQJgAiCBEAEQQIggiABEEGQAIggSABEECQAIggSABEECYAIggRABEECIIIgARBB\nkACIIEgARBAkACIIEgARBAmACIIEQARBAiCCIAEQQZAAiCBIAEQQJAAiCBIAEQQJgAiCBEAEQQIg\ngiABEEGQAIggSABEECQAIrwbd7iu65qmmU6nk8mkKIr5fD7u+ACcq5GDtN1u1+v1/nLbtm3blmU5\n7l0AcJZGXrJbLpfD5bIs27Ydd3wAztUJ9yHVdW3zCIAnOkmQ6rr+8OFDURSCBMATfXV3d/f0W/d9\n3zTN/Z8frtQNVqvVdDr91+Mavvrqq6dPAIBX9/PPP//000/jj3t3SovF4l9vM/5DAuCUPn78eIpk\nOA8JgAhjBqnrur7vh6uHlwHgcWOeh1QURV3X+7Ni9/99cN8SANw3ZpCm0+lwViwAPIt9SABEECQA\nIggSABEECYAIggRABEECIIIgARBBkACIIEgARBAkACIIEgARBAmACIIEQARBAiCCIAEQQZAAiCBI\nAEQQJAAiCBIAEQQJgAiCBEAEQQIggiABEEGQAIggSABEECQAIggSABEECYAIggRABEECIIIgARBB\nkACIIEgARBAkACIIEgARBAmACIIEQARBAiCCIAEQQZAAiCBIAEQQJAAiCBIAEQQJgAiCBEAEQQIg\ngiABEEGQAIggSABEECQAIggSABFOFaSLi4umaU40OADn5yRBquu6qqq+708xOABnafwg9X3f931V\nVaOPDMAZGz9IdV0vl8vRhwXgvI0cpLZti6IoimLcYQHIcXt7e4ph3z3r1n3fP3iowr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SABEECQAIggSABEECYAIggRAhP8HJUscDjw38SYAAAAASUVORK5CYII=\n",
"text/plain": [
- ""
+ ""
]
},
"metadata": {},
@@ -349,7 +203,7 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 3,
"metadata": {
"collapsed": false,
"slideshow": {
@@ -361,39 +215,21 @@
"name": "stdout",
"output_type": "stream",
"text": [
- "'incsearch' is a function from the file /home/ryan/Documents/UConn/ME3255/course_git_F2017/06_roots and optimization/incsearch.m\n",
- "\n",
- " incsearch: incremental search root locator\n",
- " xb = incsearch(func,xmin,xmax,ns):\n",
- " finds brackets of x that contain sign changes\n",
- " of a function on an interval\n",
- " input:\n",
- " func = name of function\n",
- " xmin, xmax = endpoints of interval\n",
- " ns = number of subintervals (default = 50)\n",
- " output:\n",
- " xb(k,1) is the lower bound of the kth sign change\n",
- " xb(k,2) is the upper bound of the kth sign change\n",
- " If no brackets found, xb = [].\n",
- "\n",
- "\n",
- "Additional help for built-in functions and operators is\n",
- "available in the online version of the manual. Use the command\n",
- "'doc ' to search the manual index.\n",
+ "number of brackets: 1\n",
+ "ans =\n",
"\n",
- "Help and information about Octave is also available on the WWW\n",
- "at http://www.octave.org and via the help@octave.org\n",
- "mailing list.\n"
+ " 141.84 144.90\n",
+ "\n"
]
}
],
"source": [
- "help incsearch"
+ "incsearch(f_m,50,200)"
]
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": 4,
"metadata": {
"collapsed": false,
"scrolled": true,
@@ -627,7 +463,7 @@
},
{
"cell_type": "code",
- "execution_count": 21,
+ "execution_count": 9,
"metadata": {
"collapsed": false,
"scrolled": true,
@@ -764,13 +600,13 @@
"\tgnuplot_plot_3a\n",
"\n",
"\t \n",
- "\t\n",
+ "\t\n",
"\n",
"\t\n",
"\tgnuplot_plot_4a\n",
"\n",
- "\t\t \n",
- "\t\n",
+ "\t\t \n",
+ "\t\n",
"\n",
"\t\n",
"\n",
diff --git a/06_roots-1/octave-workspace b/06_roots-1/octave-workspace
index 05454da..3a964d4 100644
Binary files a/06_roots-1/octave-workspace and b/06_roots-1/octave-workspace differ
diff --git a/07_roots-2/octave-workspace b/07_roots-2/octave-workspace
index 70eb62b..8c437bb 100644
Binary files a/07_roots-2/octave-workspace and b/07_roots-2/octave-workspace differ
diff --git a/08_optimization/.ipynb_checkpoints/lecture_08-checkpoint.ipynb b/08_optimization/.ipynb_checkpoints/lecture_08-checkpoint.ipynb
new file mode 100644
index 0000000..fa0f10b
--- /dev/null
+++ b/08_optimization/.ipynb_checkpoints/lecture_08-checkpoint.ipynb
@@ -0,0 +1,2836 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "skip"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "%plot --format svg"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "# Optimization"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "fragment"
+ }
+ },
+ "source": [
+ "Many problems involve finding a minimum or maximum based on given constraints. Engineers and scientists typically use energy balance equations to find the conditions of minimum energy, but this value may never go to 0 and the actual value of energy may not be of interest. "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "# Lennard-Jones potential"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "fragment"
+ }
+ },
+ "source": [
+ "The Lennard-Jones potential is commonly used to model interatomic bonding. \n",
+ "\n",
+ "$E_{LJ}(x)=4\\epsilon \\left(\\left(\\frac{\\sigma}{x}\\right)^{12}-\\left(\\frac{\\sigma}{x}\\right)^{6}\\right)$\n",
+ "\n",
+ "Considering a 1-D gold chain, we can calculate the bond length, $x_{b}$, with no force applied to the chain and even for tension, F. This will allow us to calculate the nonlinear spring constant of a 1-D gold chain. \n",
+ "\n",
+ "![TEM image of Gold chain](au_chain.jpg)\n",
+ "\n",
+ "Computational Tools to Study and Predict the Long-Term Stability of Nanowires.\n",
+ "By Martin E. Zoloff Michoff, Patricio VĂ©lez, Sergio A. Dassie and Ezequiel P. M. Leiva "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "source": [
+ "![Model of Gold chain, from molecular dynamics simulation](Auchain_model.png)\n",
+ "\n",
+ "[Single atom gold chain mechanics](http://www.uam.es/personal_pdi/ciencias/agrait/)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "### First, let's find the minimum energy $\\min(E_{LJ}(x))$\n",
+ "\n",
+ "## Brute force"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "setdefaults\n",
+ "epsilon = 0.039; % kcal/mol\n",
+ "sigma = 2.934; % Angstrom\n",
+ "x=linspace(2.8,6,200); % bond length in Angstrom\n",
+ "\n",
+ "Ex = lennard_jones(x,sigma,epsilon);\n",
+ "\n",
+ "[Emin,imin]=min(Ex);\n",
+ "\n",
+ "plot(x,Ex,x(imin),Emin,'o')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "ans = 3.2824\n",
+ "ans = 3.2985\n",
+ "ans = 3.3146\n"
+ ]
+ }
+ ],
+ "source": [
+ "x(imin-1)\n",
+ "x(imin)\n",
+ "x(imin+1)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "## Golden Search Algorithm\n",
+ "\n",
+ "We can't just look for a sign change for the problem (unless we can take a derivative) so we need a new approach to determine whether we have a maximum between the two bounds.\n",
+ "\n",
+ "Rather than using the midpoint of initial bounds, here the problem is more difficult. We need to compare the values of 4 function evaluations. The golden search uses the golden ratio to determine two interior points. \n",
+ "\n",
+ "![golden ratio](goldenratio.png)\n",
+ "\n",
+ "Start with bounds of 2.5 and 6 Angstrom. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "current_min = -0.019959\r\n"
+ ]
+ },
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "% define Au atomic potential\n",
+ "epsilon = 0.039; % kcal/mol\n",
+ "sigma = 2.934; % Angstrom\n",
+ "Au_x= @(x) lennard_jones(x,sigma,epsilon);\n",
+ "\n",
+ "% calculate golden ratio\n",
+ "phi = 1/2+sqrt(5)/2;\n",
+ "% set initial limits\n",
+ "x_l=2.8; \n",
+ "x_u=6; \n",
+ "\n",
+ "% Iteration #1\n",
+ "d=(phi-1)*(x_u-x_l);\n",
+ "\n",
+ "x1=x_l+d; % define point 1\n",
+ "x2=x_u-d; % define point 2\n",
+ "\n",
+ "\n",
+ "% evaluate Au_x(x1) and Au_x(x2)\n",
+ "\n",
+ "f1=Au_x(x1);\n",
+ "f2=Au_x(x2);\n",
+ "plot(x,Au_x(x),x_l,Au_x(x_l),'ro',x2,f2,'rs',x1,f1,'gs',x_u,Au_x(x_u),'go')\n",
+ "hold on;\n",
+ "\n",
+ "if f2\n",
+ "\n",
+ "Gnuplot\n",
+ "Produced by GNUPLOT 5.0 patchlevel 3 \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.04\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.02\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.02\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.04\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.06\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.08\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t2.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t3\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t3.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t4\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t4.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t5.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t6\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\tgnuplot_plot_1a\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\tgnuplot_plot_2a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_3a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_4a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_5a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_6a\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "% Iteration #2\n",
+ "d=(phi-1)*(x_u-x_l);\n",
+ "\n",
+ "x1=x_l+d; % define point 1\n",
+ "x2=x_u-d; % define point 2\n",
+ "\n",
+ "% evaluate Au_x(x1) and Au_x(x2)\n",
+ "\n",
+ "f1=Au_x(x1);\n",
+ "f2=Au_x(x2);\n",
+ "plot(x,Au_x(x),x_l,Au_x(x_l),'ro',x2,f2,'rs',x1,f1,'gs',x_u,Au_x(x_u),'go')\n",
+ "hold on;\n",
+ "\n",
+ "if f2\n",
+ "\n",
+ "Gnuplot\n",
+ "Produced by GNUPLOT 5.0 patchlevel 3 \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t \n",
+ "\t \n",
+ "\t\n",
+ "\t\n",
+ "\t \n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.04\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.02\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.02\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.04\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.06\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.08\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t2.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t3\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t3.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t4\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t4.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t5.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t6\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\tgnuplot_plot_1a\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\tgnuplot_plot_2a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_3a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_4a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_5a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_6a\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "% Iteration #3\n",
+ "d=(phi-1)*(x_u-x_l);\n",
+ "\n",
+ "x1=x_l+d; % define point 1\n",
+ "x2=x_u-d; % define point 2\n",
+ "\n",
+ "% evaluate Au_x(x1) and Au_x(x2)\n",
+ "\n",
+ "f1=Au_x(x1);\n",
+ "f2=Au_x(x2);\n",
+ "plot(x,Au_x(x),x_l,Au_x(x_l),'ro',x2,f2,'rs',x1,f1,'gs',x_u,Au_x(x_u),'go')\n",
+ "hold on;\n",
+ "\n",
+ "if f2\n",
+ "\n",
+ "Gnuplot\n",
+ "Produced by GNUPLOT 5.0 patchlevel 3 \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t \n",
+ "\t \n",
+ "\t\n",
+ "\t\n",
+ "\t \n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.04\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.02\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.02\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.04\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.06\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.08\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t2.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t3\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t3.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t4\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t4.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t5.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t6\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\tgnuplot_plot_1a\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\tgnuplot_plot_2a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_3a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_4a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_5a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_6a\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "% Iteration #3\n",
+ "d=(phi-1)*(x_u-x_l);\n",
+ "\n",
+ "x1=x_l+d; % define point 1\n",
+ "x2=x_u-d; % define point 2\n",
+ "\n",
+ "% evaluate Au_x(x1) and Au_x(x2)\n",
+ "\n",
+ "f1=Au_x(x1);\n",
+ "f2=Au_x(x2);\n",
+ "plot(x,Au_x(x),x_l,Au_x(x_l),'ro',x2,f2,'rs',x1,f1,'gs',x_u,Au_x(x_u),'go')\n",
+ "hold on;\n",
+ "\n",
+ "if f2\n",
+ "\n",
+ "Gnuplot\n",
+ "Produced by GNUPLOT 5.0 patchlevel 3 \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t \n",
+ "\t \n",
+ "\t\n",
+ "\t\n",
+ "\t \n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.06\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.04\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.02\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.02\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.04\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.06\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.08\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t2.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t3\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t3.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t4\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t4.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t5.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t6\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\tgnuplot_plot_1a\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\tgnuplot_plot_2a\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\tgnuplot_plot_3a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_4a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_5a\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "% define Au atomic potential\n",
+ "epsilon = 0.039; % kcal/mol\n",
+ "sigma = 2.934; % Angstrom\n",
+ "Au_x= @(x) lennard_jones(x,sigma,epsilon);\n",
+ "\n",
+ "% set initial limits\n",
+ "x_l=2.8; \n",
+ "x_u=3.5; \n",
+ "\n",
+ "% Iteration #1\n",
+ "x1=x_l;\n",
+ "x2=mean([x_l,x_u]);\n",
+ "x3=x_u;\n",
+ "\n",
+ "% evaluate Au_x(x1), Au_x(x2) and Au_x(x3)\n",
+ " \n",
+ "f1=Au_x(x1);\n",
+ "f2=Au_x(x2);\n",
+ "f3=Au_x(x3);\n",
+ "p = polyfit([x1,x2,x3],[f1,f2,f3],2);\n",
+ "x_fit = linspace(x1,x3,20);\n",
+ "y_fit = polyval(p,x_fit);\n",
+ "\n",
+ "plot(x,Au_x(x),x_fit,y_fit,[x1,x2,x3],[f1,f2,f3],'o')\n",
+ "hold on\n",
+ "if f2x2\n",
+ " plot(x4,f4,'*',[x1,x2],[f1,f2])\n",
+ " x1=x2;\n",
+ " f1=f2;\n",
+ " else\n",
+ " plot(x4,f4,'*',[x3,x2],[f3,f2])\n",
+ " x3=x2;\n",
+ " f3=f2;\n",
+ " end\n",
+ " x2=x4; f2=f4;\n",
+ "else\n",
+ " error('no minimum in bracket')\n",
+ "end\n",
+ "hold off"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "p = polyfit([x1,x2,x3],[f1,f2,f3],2);\n",
+ "x_fit = linspace(x1,x3,20);\n",
+ "y_fit = polyval(p,x_fit);\n",
+ "\n",
+ "plot(x,Au_x(x),x_fit,y_fit,[x1,x2,x3],[f1,f2,f3],'o')\n",
+ "hold on\n",
+ "if f2x2\n",
+ " plot(x4,f4,'*',[x1,x2],[f1,f2])\n",
+ " x1=x2;\n",
+ " f1=f2;\n",
+ " else\n",
+ " plot(x4,f4,'*',[x3,x2],[f3,f2])\n",
+ " x3=x2;\n",
+ " f3=f2;\n",
+ " end\n",
+ " x2=x4; f2=f4;\n",
+ "else\n",
+ " error('no minimum in bracket')\n",
+ "end\n",
+ "hold off\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "p = polyfit([x1,x2,x3],[f1,f2,f3],2);\n",
+ "x_fit = linspace(x1,x3,20);\n",
+ "y_fit = polyval(p,x_fit);\n",
+ "\n",
+ "plot(x,Au_x(x),x_fit,y_fit,[x1,x2,x3],[f1,f2,f3],'o')\n",
+ "hold on\n",
+ "if f2x2\n",
+ " plot(x4,f4,'*',[x1,x2],[f1,f2])\n",
+ " x1=x2;\n",
+ " f1=f2;\n",
+ " else\n",
+ " plot(x4,f4,'*',[x3,x2],[f3,f2])\n",
+ " x3=x2;\n",
+ " f3=f2;\n",
+ " end\n",
+ " x2=x4; f2=f4;\n",
+ "else\n",
+ " error('no minimum in bracket')\n",
+ "end\n",
+ "hold off\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "source": [
+ "Parabolic interpolation does not converge in many scenarios even though it it a bracketing method. Instead, functions like `fminbnd` in Matlab and Octave use a combination of the two (Golden Ratio and Parabolic)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "## Using the solutions to minimization for the nonlinear spring constant\n",
+ "\n",
+ "Now, we have two routines to find minimums of a univariate function (Golden Ratio and Parabolic). Let's use these to solve for the minimum energy given a range of applied forces to the single atom gold chain\n",
+ "\n",
+ "$E_{total}(\\Delta x) = E_{LJ}(x_{min}+\\Delta x) - F \\cdot \\Delta x$\n",
+ "\n",
+ "$1 aJ = 10^{-18} J = 1~nN* 1~nm = 10^{-9}N * 10^{-9} m$"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "warning: Matlab-style short-circuit operation performed for operator |\n",
+ "warning: called from\n",
+ " goldmin at line 17 column 1\n",
+ "warning: Matlab-style short-circuit operation performed for operator |\n",
+ "warning: Matlab-style short-circuit operation performed for operator |\n",
+ "xmin = 0.32933\n",
+ "Emin = -2.7096e-04\n"
+ ]
+ },
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "epsilon = 0.039; % kcal/mol\n",
+ "epsilon = epsilon*6.9477e-21; % J/atom\n",
+ "epsilon = epsilon*1e18; % aJ/J\n",
+ "% final units for epsilon are aJ\n",
+ "\n",
+ "sigma = 2.934; % Angstrom\n",
+ "sigma = sigma*0.10; % nm/Angstrom\n",
+ "x=linspace(2.8,6,200)*0.10; % bond length in um\n",
+ "\n",
+ "Ex = lennard_jones(x,sigma,epsilon);\n",
+ "\n",
+ "%[Emin,imin]=min(Ex);\n",
+ "\n",
+ "[xmin,Emin] = goldmin(@(x) lennard_jones(x,sigma,epsilon),0.28,0.6)\n",
+ "\n",
+ "plot(x,Ex,xmin,Emin,'o')\n",
+ "ylabel('Lennard Jones Potential (aJ/atom)')\n",
+ "xlabel('bond length (nm)')\n",
+ "\n",
+ "Etotal = @(dx,F) lennard_jones(xmin+dx,sigma,epsilon)-F.*dx;\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "N=50;\n",
+ "warning('off')\n",
+ "dx = zeros(1,N); % [in nm]\n",
+ "F_applied=linspace(0,0.0022,N); % [in nN]\n",
+ "for i=1:N\n",
+ " optmin=goldmin(@(dx) Etotal(dx,F_applied(i)),-0.001,0.035);\n",
+ " dx(i)=optmin;\n",
+ "end\n",
+ "\n",
+ "plot(dx,F_applied)\n",
+ "xlabel('dx (nm)')\n",
+ "ylabel('Force (nN)')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "For this function, it is possible to take a derivative and compare the analytical result:\n",
+ "\n",
+ "dE/dx = 0 = d(E_LJ)/dx - F\n",
+ "\n",
+ "F= d(E_LJ)/dx"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 32,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "F =\n",
+ "\n",
+ "@(dx) 4 * epsilon * 6 * (sigma ^ 6 ./ (xmin + dx) .^ 7 - 2 * sigma ^ 12 ./ (xmin + dx) .^ 13)\n",
+ "\n"
+ ]
+ },
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "dx_full=linspace(0,0.06,50);\n",
+ "F= @(dx) 4*epsilon*6*(sigma^6./(xmin+dx).^7-2*sigma^12./(xmin+dx).^13)\n",
+ "plot(dx_full,F(dx_full),dx,F_applied)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "collapsed": true,
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "## Curve-fitting\n",
+ "Another example is minimizing error in your approximation of a function. If you have data (now we have Force-displacement data) we can fit this to a function, such as:\n",
+ "\n",
+ "$F(x) = K_{1}\\Delta x + \\frac{1}{2} K_{2}(\\Delta x)^{2}$\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "function SSE = sse_of_parabola(K,xdata,ydata)\n",
+ " % calculate the sum of squares error for a parabola given a function, func, and xdata and ydata\n",
+ " % output is SSE=sum of squares error\n",
+ " K1=K(1);\n",
+ " K2=K(2);\n",
+ " y_function = K1*xdata+1/2*K2*xdata.^2;\n",
+ " SSE = sum((ydata-y_function).^2);\n",
+ "end\n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 34,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "The nonlinear spring constants are K1=0.16 nN/nm and K2=-5.98 nN/nm^2\n",
+ "The mininum sum of squares error = 7.35e-08\n"
+ ]
+ }
+ ],
+ "source": [
+ "[K,SSE_min]=fminsearch(@(K) sse_of_parabola(K,dx,F_applied),[1,1]);\n",
+ "fprintf('\\nThe nonlinear spring constants are K1=%1.2f nN/nm and K2=%1.2f nN/nm^2\\n',K)\n",
+ "fprintf('The mininum sum of squares error = %1.2e',SSE_min)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "plot(dx,F_applied,'o',dx,K(1)*dx+1/2*K(2)*dx.^2)"
+ ]
+ }
+ ],
+ "metadata": {
+ "celltoolbar": "Slideshow",
+ "kernelspec": {
+ "display_name": "Octave",
+ "language": "octave",
+ "name": "octave"
+ },
+ "language_info": {
+ "file_extension": ".m",
+ "help_links": [
+ {
+ "text": "MetaKernel Magics",
+ "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
+ }
+ ],
+ "mimetype": "text/x-octave",
+ "name": "octave",
+ "version": "0.19.14"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/08_optimization/Auchain_model.gif b/08_optimization/Auchain_model.gif
new file mode 100644
index 0000000..2f8c78c
Binary files /dev/null and b/08_optimization/Auchain_model.gif differ
diff --git a/08_optimization/Auchain_model.png b/08_optimization/Auchain_model.png
new file mode 100644
index 0000000..dce9cd7
Binary files /dev/null and b/08_optimization/Auchain_model.png differ
diff --git a/08_optimization/au_chain.jpg b/08_optimization/au_chain.jpg
new file mode 100644
index 0000000..492fee8
Binary files /dev/null and b/08_optimization/au_chain.jpg differ
diff --git a/08_optimization/goldenratio.png b/08_optimization/goldenratio.png
new file mode 100644
index 0000000..9493c8c
Binary files /dev/null and b/08_optimization/goldenratio.png differ
diff --git a/08_optimization/goldmin.m b/08_optimization/goldmin.m
new file mode 100644
index 0000000..fb4ce0b
--- /dev/null
+++ b/08_optimization/goldmin.m
@@ -0,0 +1,36 @@
+function [x,fx,ea,iter]=goldmin(f,xl,xu,es,maxit,varargin)
+% goldmin: minimization golden section search
+% [x,fx,ea,iter]=goldmin(f,xl,xu,es,maxit,p1,p2,...):
+% uses golden section search to find the minimum of f
+% input:
+% f = name of function
+% xl, xu = lower and upper guesses
+% es = desired relative error (default = 0.0001%)
+% maxit = maximum allowable iterations (default = 50)
+% p1,p2,... = additional parameters used by f
+% output:
+% x = location of minimum
+% fx = minimum function value
+% ea = approximate relative error (%)
+% iter = number of iterations
+if nargin<3,error('at least 3 input arguments required'),end
+if nargin<4|isempty(es), es=0.0001;end
+if nargin<5|isempty(maxit), maxit=50;end
+phi=(1+sqrt(5))/2;
+iter=0;
+while(1)
+ d = (phi-1)*(xu - xl);
+ x1 = xl + d;
+ x2 = xu - d;
+ if f(x1,varargin{:}) < f(x2,varargin{:})
+ xopt = x1;
+ xl = x2;
+ else
+ xopt = x2;
+ xu = x1;
+ end
+ iter=iter+1;
+ if xopt~=0, ea = (2 - phi) * abs((xu - xl) / xopt) * 100;end
+ if ea <= es | iter >= maxit,break,end
+end
+x=xopt;fx=f(xopt,varargin{:});
diff --git a/08_optimization/lecture_08.ipynb b/08_optimization/lecture_08.ipynb
new file mode 100644
index 0000000..fa0f10b
--- /dev/null
+++ b/08_optimization/lecture_08.ipynb
@@ -0,0 +1,2836 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "skip"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "%plot --format svg"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "# Optimization"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "fragment"
+ }
+ },
+ "source": [
+ "Many problems involve finding a minimum or maximum based on given constraints. Engineers and scientists typically use energy balance equations to find the conditions of minimum energy, but this value may never go to 0 and the actual value of energy may not be of interest. "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "# Lennard-Jones potential"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "fragment"
+ }
+ },
+ "source": [
+ "The Lennard-Jones potential is commonly used to model interatomic bonding. \n",
+ "\n",
+ "$E_{LJ}(x)=4\\epsilon \\left(\\left(\\frac{\\sigma}{x}\\right)^{12}-\\left(\\frac{\\sigma}{x}\\right)^{6}\\right)$\n",
+ "\n",
+ "Considering a 1-D gold chain, we can calculate the bond length, $x_{b}$, with no force applied to the chain and even for tension, F. This will allow us to calculate the nonlinear spring constant of a 1-D gold chain. \n",
+ "\n",
+ "![TEM image of Gold chain](au_chain.jpg)\n",
+ "\n",
+ "Computational Tools to Study and Predict the Long-Term Stability of Nanowires.\n",
+ "By Martin E. Zoloff Michoff, Patricio VĂ©lez, Sergio A. Dassie and Ezequiel P. M. Leiva "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "source": [
+ "![Model of Gold chain, from molecular dynamics simulation](Auchain_model.png)\n",
+ "\n",
+ "[Single atom gold chain mechanics](http://www.uam.es/personal_pdi/ciencias/agrait/)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "### First, let's find the minimum energy $\\min(E_{LJ}(x))$\n",
+ "\n",
+ "## Brute force"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "setdefaults\n",
+ "epsilon = 0.039; % kcal/mol\n",
+ "sigma = 2.934; % Angstrom\n",
+ "x=linspace(2.8,6,200); % bond length in Angstrom\n",
+ "\n",
+ "Ex = lennard_jones(x,sigma,epsilon);\n",
+ "\n",
+ "[Emin,imin]=min(Ex);\n",
+ "\n",
+ "plot(x,Ex,x(imin),Emin,'o')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "ans = 3.2824\n",
+ "ans = 3.2985\n",
+ "ans = 3.3146\n"
+ ]
+ }
+ ],
+ "source": [
+ "x(imin-1)\n",
+ "x(imin)\n",
+ "x(imin+1)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "## Golden Search Algorithm\n",
+ "\n",
+ "We can't just look for a sign change for the problem (unless we can take a derivative) so we need a new approach to determine whether we have a maximum between the two bounds.\n",
+ "\n",
+ "Rather than using the midpoint of initial bounds, here the problem is more difficult. We need to compare the values of 4 function evaluations. The golden search uses the golden ratio to determine two interior points. \n",
+ "\n",
+ "![golden ratio](goldenratio.png)\n",
+ "\n",
+ "Start with bounds of 2.5 and 6 Angstrom. "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "current_min = -0.019959\r\n"
+ ]
+ },
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "% define Au atomic potential\n",
+ "epsilon = 0.039; % kcal/mol\n",
+ "sigma = 2.934; % Angstrom\n",
+ "Au_x= @(x) lennard_jones(x,sigma,epsilon);\n",
+ "\n",
+ "% calculate golden ratio\n",
+ "phi = 1/2+sqrt(5)/2;\n",
+ "% set initial limits\n",
+ "x_l=2.8; \n",
+ "x_u=6; \n",
+ "\n",
+ "% Iteration #1\n",
+ "d=(phi-1)*(x_u-x_l);\n",
+ "\n",
+ "x1=x_l+d; % define point 1\n",
+ "x2=x_u-d; % define point 2\n",
+ "\n",
+ "\n",
+ "% evaluate Au_x(x1) and Au_x(x2)\n",
+ "\n",
+ "f1=Au_x(x1);\n",
+ "f2=Au_x(x2);\n",
+ "plot(x,Au_x(x),x_l,Au_x(x_l),'ro',x2,f2,'rs',x1,f1,'gs',x_u,Au_x(x_u),'go')\n",
+ "hold on;\n",
+ "\n",
+ "if f2\n",
+ "\n",
+ "Gnuplot\n",
+ "Produced by GNUPLOT 5.0 patchlevel 3 \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t \n",
+ "\t \n",
+ "\t\n",
+ "\t\n",
+ "\t \n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.04\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.02\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.02\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.04\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.06\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.08\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t2.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t3\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t3.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t4\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t4.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t5.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t6\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\tgnuplot_plot_1a\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\tgnuplot_plot_2a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_3a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_4a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_5a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_6a\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "% Iteration #2\n",
+ "d=(phi-1)*(x_u-x_l);\n",
+ "\n",
+ "x1=x_l+d; % define point 1\n",
+ "x2=x_u-d; % define point 2\n",
+ "\n",
+ "% evaluate Au_x(x1) and Au_x(x2)\n",
+ "\n",
+ "f1=Au_x(x1);\n",
+ "f2=Au_x(x2);\n",
+ "plot(x,Au_x(x),x_l,Au_x(x_l),'ro',x2,f2,'rs',x1,f1,'gs',x_u,Au_x(x_u),'go')\n",
+ "hold on;\n",
+ "\n",
+ "if f2\n",
+ "\n",
+ "Gnuplot\n",
+ "Produced by GNUPLOT 5.0 patchlevel 3 \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t \n",
+ "\t \n",
+ "\t\n",
+ "\t\n",
+ "\t \n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.04\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.02\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.02\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.04\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.06\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.08\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t2.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t3\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t3.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t4\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t4.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t5.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t6\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\tgnuplot_plot_1a\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\tgnuplot_plot_2a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_3a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_4a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_5a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_6a\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "% Iteration #3\n",
+ "d=(phi-1)*(x_u-x_l);\n",
+ "\n",
+ "x1=x_l+d; % define point 1\n",
+ "x2=x_u-d; % define point 2\n",
+ "\n",
+ "% evaluate Au_x(x1) and Au_x(x2)\n",
+ "\n",
+ "f1=Au_x(x1);\n",
+ "f2=Au_x(x2);\n",
+ "plot(x,Au_x(x),x_l,Au_x(x_l),'ro',x2,f2,'rs',x1,f1,'gs',x_u,Au_x(x_u),'go')\n",
+ "hold on;\n",
+ "\n",
+ "if f2\n",
+ "\n",
+ "Gnuplot\n",
+ "Produced by GNUPLOT 5.0 patchlevel 3 \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t \n",
+ "\t \n",
+ "\t\n",
+ "\t\n",
+ "\t \n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.04\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.02\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.02\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.04\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.06\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.08\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t2.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t3\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t3.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t4\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t4.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t5.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t6\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\tgnuplot_plot_1a\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\tgnuplot_plot_2a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_3a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_4a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_5a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_6a\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "% Iteration #3\n",
+ "d=(phi-1)*(x_u-x_l);\n",
+ "\n",
+ "x1=x_l+d; % define point 1\n",
+ "x2=x_u-d; % define point 2\n",
+ "\n",
+ "% evaluate Au_x(x1) and Au_x(x2)\n",
+ "\n",
+ "f1=Au_x(x1);\n",
+ "f2=Au_x(x2);\n",
+ "plot(x,Au_x(x),x_l,Au_x(x_l),'ro',x2,f2,'rs',x1,f1,'gs',x_u,Au_x(x_u),'go')\n",
+ "hold on;\n",
+ "\n",
+ "if f2\n",
+ "\n",
+ "Gnuplot\n",
+ "Produced by GNUPLOT 5.0 patchlevel 3 \n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\t \n",
+ "\t \n",
+ "\t\n",
+ "\t\n",
+ "\t \n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.06\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.04\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t-0.02\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.02\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.04\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.06\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t0.08\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t2.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t3\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t3.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t4\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t4.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t5.5\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\t\t\n",
+ "\t\t6\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\tgnuplot_plot_1a\n",
+ "\n",
+ "\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\tgnuplot_plot_2a\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\tgnuplot_plot_3a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\t\n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_4a\n",
+ "\n",
+ "\t \n",
+ "\t\n",
+ "\n",
+ "\t\n",
+ "\tgnuplot_plot_5a\n",
+ "\n",
+ "\t\n",
+ "\t\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ "\n",
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "% define Au atomic potential\n",
+ "epsilon = 0.039; % kcal/mol\n",
+ "sigma = 2.934; % Angstrom\n",
+ "Au_x= @(x) lennard_jones(x,sigma,epsilon);\n",
+ "\n",
+ "% set initial limits\n",
+ "x_l=2.8; \n",
+ "x_u=3.5; \n",
+ "\n",
+ "% Iteration #1\n",
+ "x1=x_l;\n",
+ "x2=mean([x_l,x_u]);\n",
+ "x3=x_u;\n",
+ "\n",
+ "% evaluate Au_x(x1), Au_x(x2) and Au_x(x3)\n",
+ " \n",
+ "f1=Au_x(x1);\n",
+ "f2=Au_x(x2);\n",
+ "f3=Au_x(x3);\n",
+ "p = polyfit([x1,x2,x3],[f1,f2,f3],2);\n",
+ "x_fit = linspace(x1,x3,20);\n",
+ "y_fit = polyval(p,x_fit);\n",
+ "\n",
+ "plot(x,Au_x(x),x_fit,y_fit,[x1,x2,x3],[f1,f2,f3],'o')\n",
+ "hold on\n",
+ "if f2x2\n",
+ " plot(x4,f4,'*',[x1,x2],[f1,f2])\n",
+ " x1=x2;\n",
+ " f1=f2;\n",
+ " else\n",
+ " plot(x4,f4,'*',[x3,x2],[f3,f2])\n",
+ " x3=x2;\n",
+ " f3=f2;\n",
+ " end\n",
+ " x2=x4; f2=f4;\n",
+ "else\n",
+ " error('no minimum in bracket')\n",
+ "end\n",
+ "hold off"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "p = polyfit([x1,x2,x3],[f1,f2,f3],2);\n",
+ "x_fit = linspace(x1,x3,20);\n",
+ "y_fit = polyval(p,x_fit);\n",
+ "\n",
+ "plot(x,Au_x(x),x_fit,y_fit,[x1,x2,x3],[f1,f2,f3],'o')\n",
+ "hold on\n",
+ "if f2x2\n",
+ " plot(x4,f4,'*',[x1,x2],[f1,f2])\n",
+ " x1=x2;\n",
+ " f1=f2;\n",
+ " else\n",
+ " plot(x4,f4,'*',[x3,x2],[f3,f2])\n",
+ " x3=x2;\n",
+ " f3=f2;\n",
+ " end\n",
+ " x2=x4; f2=f4;\n",
+ "else\n",
+ " error('no minimum in bracket')\n",
+ "end\n",
+ "hold off\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "p = polyfit([x1,x2,x3],[f1,f2,f3],2);\n",
+ "x_fit = linspace(x1,x3,20);\n",
+ "y_fit = polyval(p,x_fit);\n",
+ "\n",
+ "plot(x,Au_x(x),x_fit,y_fit,[x1,x2,x3],[f1,f2,f3],'o')\n",
+ "hold on\n",
+ "if f2x2\n",
+ " plot(x4,f4,'*',[x1,x2],[f1,f2])\n",
+ " x1=x2;\n",
+ " f1=f2;\n",
+ " else\n",
+ " plot(x4,f4,'*',[x3,x2],[f3,f2])\n",
+ " x3=x2;\n",
+ " f3=f2;\n",
+ " end\n",
+ " x2=x4; f2=f4;\n",
+ "else\n",
+ " error('no minimum in bracket')\n",
+ "end\n",
+ "hold off\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "source": [
+ "Parabolic interpolation does not converge in many scenarios even though it it a bracketing method. Instead, functions like `fminbnd` in Matlab and Octave use a combination of the two (Golden Ratio and Parabolic)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "## Using the solutions to minimization for the nonlinear spring constant\n",
+ "\n",
+ "Now, we have two routines to find minimums of a univariate function (Golden Ratio and Parabolic). Let's use these to solve for the minimum energy given a range of applied forces to the single atom gold chain\n",
+ "\n",
+ "$E_{total}(\\Delta x) = E_{LJ}(x_{min}+\\Delta x) - F \\cdot \\Delta x$\n",
+ "\n",
+ "$1 aJ = 10^{-18} J = 1~nN* 1~nm = 10^{-9}N * 10^{-9} m$"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "warning: Matlab-style short-circuit operation performed for operator |\n",
+ "warning: called from\n",
+ " goldmin at line 17 column 1\n",
+ "warning: Matlab-style short-circuit operation performed for operator |\n",
+ "warning: Matlab-style short-circuit operation performed for operator |\n",
+ "xmin = 0.32933\n",
+ "Emin = -2.7096e-04\n"
+ ]
+ },
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "epsilon = 0.039; % kcal/mol\n",
+ "epsilon = epsilon*6.9477e-21; % J/atom\n",
+ "epsilon = epsilon*1e18; % aJ/J\n",
+ "% final units for epsilon are aJ\n",
+ "\n",
+ "sigma = 2.934; % Angstrom\n",
+ "sigma = sigma*0.10; % nm/Angstrom\n",
+ "x=linspace(2.8,6,200)*0.10; % bond length in um\n",
+ "\n",
+ "Ex = lennard_jones(x,sigma,epsilon);\n",
+ "\n",
+ "%[Emin,imin]=min(Ex);\n",
+ "\n",
+ "[xmin,Emin] = goldmin(@(x) lennard_jones(x,sigma,epsilon),0.28,0.6)\n",
+ "\n",
+ "plot(x,Ex,xmin,Emin,'o')\n",
+ "ylabel('Lennard Jones Potential (aJ/atom)')\n",
+ "xlabel('bond length (nm)')\n",
+ "\n",
+ "Etotal = @(dx,F) lennard_jones(xmin+dx,sigma,epsilon)-F.*dx;\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 31,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "N=50;\n",
+ "warning('off')\n",
+ "dx = zeros(1,N); % [in nm]\n",
+ "F_applied=linspace(0,0.0022,N); % [in nN]\n",
+ "for i=1:N\n",
+ " optmin=goldmin(@(dx) Etotal(dx,F_applied(i)),-0.001,0.035);\n",
+ " dx(i)=optmin;\n",
+ "end\n",
+ "\n",
+ "plot(dx,F_applied)\n",
+ "xlabel('dx (nm)')\n",
+ "ylabel('Force (nN)')"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "For this function, it is possible to take a derivative and compare the analytical result:\n",
+ "\n",
+ "dE/dx = 0 = d(E_LJ)/dx - F\n",
+ "\n",
+ "F= d(E_LJ)/dx"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 32,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "F =\n",
+ "\n",
+ "@(dx) 4 * epsilon * 6 * (sigma ^ 6 ./ (xmin + dx) .^ 7 - 2 * sigma ^ 12 ./ (xmin + dx) .^ 13)\n",
+ "\n"
+ ]
+ },
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "dx_full=linspace(0,0.06,50);\n",
+ "F= @(dx) 4*epsilon*6*(sigma^6./(xmin+dx).^7-2*sigma^12./(xmin+dx).^13)\n",
+ "plot(dx_full,F(dx_full),dx,F_applied)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "collapsed": true,
+ "slideshow": {
+ "slide_type": "slide"
+ }
+ },
+ "source": [
+ "## Curve-fitting\n",
+ "Another example is minimizing error in your approximation of a function. If you have data (now we have Force-displacement data) we can fit this to a function, such as:\n",
+ "\n",
+ "$F(x) = K_{1}\\Delta x + \\frac{1}{2} K_{2}(\\Delta x)^{2}$\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 33,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [],
+ "source": [
+ "function SSE = sse_of_parabola(K,xdata,ydata)\n",
+ " % calculate the sum of squares error for a parabola given a function, func, and xdata and ydata\n",
+ " % output is SSE=sum of squares error\n",
+ " K1=K(1);\n",
+ " K2=K(2);\n",
+ " y_function = K1*xdata+1/2*K2*xdata.^2;\n",
+ " SSE = sum((ydata-y_function).^2);\n",
+ "end\n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 34,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "The nonlinear spring constants are K1=0.16 nN/nm and K2=-5.98 nN/nm^2\n",
+ "The mininum sum of squares error = 7.35e-08\n"
+ ]
+ }
+ ],
+ "source": [
+ "[K,SSE_min]=fminsearch(@(K) sse_of_parabola(K,dx,F_applied),[1,1]);\n",
+ "fprintf('\\nThe nonlinear spring constants are K1=%1.2f nN/nm and K2=%1.2f nN/nm^2\\n',K)\n",
+ "fprintf('The mininum sum of squares error = %1.2e',SSE_min)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 35,
+ "metadata": {
+ "collapsed": false,
+ "slideshow": {
+ "slide_type": "subslide"
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "image/svg+xml": [
+ ""
+ ],
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "plot(dx,F_applied,'o',dx,K(1)*dx+1/2*K(2)*dx.^2)"
+ ]
+ }
+ ],
+ "metadata": {
+ "celltoolbar": "Slideshow",
+ "kernelspec": {
+ "display_name": "Octave",
+ "language": "octave",
+ "name": "octave"
+ },
+ "language_info": {
+ "file_extension": ".m",
+ "help_links": [
+ {
+ "text": "MetaKernel Magics",
+ "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
+ }
+ ],
+ "mimetype": "text/x-octave",
+ "name": "octave",
+ "version": "0.19.14"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/08_optimization/lennard_jones.m b/08_optimization/lennard_jones.m
new file mode 100644
index 0000000..d18a6ad
--- /dev/null
+++ b/08_optimization/lennard_jones.m
@@ -0,0 +1,4 @@
+function E_LJ =lennard_jones(x,sigma,epsilon)
+ E_LJ = 4*epsilon*((sigma./x).^12-(sigma./x).^6);
+end
+
diff --git a/08_optimization/octave-workspace b/08_optimization/octave-workspace
new file mode 100644
index 0000000..8c437bb
Binary files /dev/null and b/08_optimization/octave-workspace differ
diff --git a/HW2/README.md b/HW2/README.md
new file mode 100644
index 0000000..a3b064d
--- /dev/null
+++ b/HW2/README.md
@@ -0,0 +1,99 @@
+# Homework #2
+## due 10/6/17 by 11:59pm
+
+
+**1\.** Create a new github repository called '02_roots_and_optimization'.
+
+ a. Add rcc02007 and zhs15101 as collaborators.
+
+ b. submit the clone repository URL to:
+ [https://goo.gl/forms/svFKpfiCfLO9Zvfz1](https://goo.gl/forms/svFKpfiCfLO9Zvfz1)
+
+
+**2\.** You're installing a powerline in a residential neighborhood. The lowest point on the
+cable is 30 m above the ground, but 30 m away is a tree that is 35 m tall. Another
+engineer informs you that this is a catenary cable problem with the following solution
+
+ $y(x)=\frac{T}{w}\cosh\left(\frac{w}{T}x\right)+y_{0}-\frac{T}{w}$.
+
+ where y(x) is the height of the cable at a distance, x, from the lowest point, $y_{0}$,
+ T is the tension in the cable, and w is the weight per unit length of the cable. Your
+ supervisor wants to know which numerical solver to use when they have to install these
+ powerlines in similar places.
+
+ a. Use the three solvers `falsepos.m`, `bisect.m`, and `mod_secant.m`
+ to solve for the tension neededi, T, to reach y(30 m)=35 m, with w=10 N/m, and $y_{0}$=30 m.
+
+ b. Compare the number of iterations that each function needed to reach an
+ accuracy of 0.00001%. Include a table in your README.md with:
+
+ ```
+ | solver | initial guess(es) | ea | number of iterations|
+ | --- | --- | --- | --- |
+ |falsepos | | | |
+ |mod_secant | | | |
+ |bisect | | | |
+ ```
+
+
+ c. Add a figure to your README that plots the final shape of the powerline
+ ($y(x)~vs.~x$) from x=-10 to 50 m.
+
+**3\.** The Newton-Raphson method and the modified secant method do not always converge to a
+solution. One simple example is the function f(x) = (x-1)*exp(-(x-1)^2). The root is at 1, but
+using the numerical solvers, `newtraph.m` and `mod_secant.m`, there are certain initial
+guesses that do not converge.
+
+ a. Calculate the first 5 iterations for the Newton-Raphson method with an initial
+ guess of x_i=3 for f(x)=(x-1)*exp(-(x-1)^2).
+
+ b. Add the results to a table in the `README.md` with:
+
+ ```
+ ### divergence of Newton-Raphson method
+
+ | iteration | x_i | approx error |
+ | --- | --- | --- |
+ | 0 | 3 | n/a |
+ | 1 | | |
+ | 2 | | |
+ | 3 | | |
+ | 4 | | |
+ | 5 | | |
+ ```
+
+ c. Repeat steps a-b for an initial guess of 1.2. (But change the heading from
+ 'divergence' to 'convergence')
+
+![Model of Gold chain, from molecular dynamics simulation](../08_optimization/Auchain_model.png)
+
+**4\.** Determine the nonlinear spring constants of a single-atom gold chain. You can assume
+the gold atoms are aligned in a one dimensional network and the potential energy is
+described by the Lennard-Jones potential as such
+
+ $E_{LJ}(x)=4\epsilon
+ \left(\left(\frac{\sigma}{x}\right)^{12}-\left(\frac{\sigma}{x}\right)^{6}\right)$.
+
+ Where x is the distance between atoms in nm, $\epsilon$=2.71E-4 aJ, and $\sigma$=0.2934
+ nm. The energy term that must be minimized is
+
+ $E_{total}(\Delta x)=E_{LJ}(x_{0}+\Delta x)-F\Delta x$.
+
+ Where $x_{0}$ is the distance between atoms with no force applied and $\Delta x$ is the
+ amount each gold atom has moved under a given force, F.
+
+ a. Determine $x_{0}$ when F=0 nN using the golden ratio and parabolic methods. *Show
+ your script and output in your README and include your functions*
+
+ b. Solve for $\Delta x$ for F=0 to 0.0022 nN with 30 steps. *Use the golden ratio
+ solver or the matlab/octave `fminsearch`
+
+ c. create a sum of squares error function `sse_of_parabola.m` that calculates the sum of
+ squares error between a function $F(x)=K_{1}\Delta x+1/2K_{2}\Delta x^{2}$ and the
+ Forces used in part B for each $\Delta x$.
+
+ d. Use the `fminsearch` matlab/octave function to determine $K_{1}$ and $K_{2}$.
+
+ e. Plot the force vs calculated $\Delta x$ and the best-fit parabola using $K_{1}$ and
+ $K_{2}$ in part d.
+