diff --git a/README.md b/README.md index 8059993..73ca14a 100644 --- a/README.md +++ b/README.md @@ -74,8 +74,8 @@ general, I will not post homework solutions. |3|1/31||Consistent Coding habits| | |2/2|5|Root Finding| |4|2/7|6|Root Finding con’d| -| |2/9|7|Optimization| -|5|2/14||Intro to Linear Algebra| +| |2/9|7| **Snow Day**| +|5|2/14|| Optimization | | |2/16|8|Linear Algebra| |6|2/21|9|Linear systems: Gauss elimination| | |2/23|10|Linear Systems: LU factorization| diff --git a/lecture_08/Auchain_model.png b/lecture_08/Auchain_model.png new file mode 100644 index 0000000..dce9cd7 Binary files /dev/null and b/lecture_08/Auchain_model.png differ diff --git a/lecture_08/goldmin.m b/lecture_08/goldmin.m index e5b0ecf..fb4ce0b 100644 --- a/lecture_08/goldmin.m +++ b/lecture_08/goldmin.m @@ -33,4 +33,4 @@ 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{:}); \ No newline at end of file +x=xopt;fx=f(xopt,varargin{:}); diff --git a/lecture_08/lecture_08.ipynb b/lecture_08/lecture_08.ipynb index d99107a..32b973c 100644 --- a/lecture_08/lecture_08.ipynb +++ b/lecture_08/lecture_08.ipynb @@ -2,7 +2,41 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 6, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "function h = parabola(x)\n", + " y=1;\n", + " h=sum(x.^2+y.^2-1);\n", + "end\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "collapsed": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ans = 0\r\n" + ] + } + ], + "source": [ + "fzero(@(x) parabola(x),1)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, "metadata": { "collapsed": false }, @@ -35,7 +69,7 @@ "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 \n", "\n", - "![Model of Gold chain, from molecular dynamics simulation](Auchain_model.gif)\n", + "![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/)\n", "\n", @@ -46,7 +80,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 11, "metadata": { "collapsed": false }, @@ -225,7 +259,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 12, "metadata": { "collapsed": false }, @@ -263,7 +297,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 13, "metadata": { "collapsed": false }, @@ -497,7 +531,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 14, "metadata": { "collapsed": false }, @@ -720,7 +754,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 15, "metadata": { "collapsed": false }, @@ -943,7 +977,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 16, "metadata": { "collapsed": false }, @@ -1174,17 +1208,14 @@ "\n", "Near a minimum/maximum, the function resembles a parabola. With three data points, it is possible to fit a parabola to the function. So, given a lower and upper bound, we can choose the midpoint and fit a parabola to the 3 x,f(x) coordinates. \n", "\n", - "$ x_{4} =x_{2} - \\frac{1}{2} \\frac{ \\left(x_{2} -x_{1} \\right)^{2} \\left[f\n", - " \\left(x_{2} \\right)-f \\left(x_{3} \\right) \\right]- \\left(x_{2} -x_{3} \\right)^{2}\n", - " \\left[f \\left(x_{2} \\right)-f \\left(x_{1} \\right) \\right]}{ \\left(x_{2} -x_{1} \\right) \\left[f \\left(x_{2} \\right)-f \\left(x_{3} \\right)\n", - " \\right]- \\left(x_{2} -x_{3} \\right) \\left[f \\left(x_{2} \\right)-f \\left(x_{1} \\right) \\right]}$\n", + "$$ x_{4} =x_{2} - \\frac{1}{2}\\frac{\\left(x_{2} -x_{1}\\right)^{2} \\left(f\\left(x_{2} \\right)-f \\left(x_{3} \\right) \\right)- \\left(x_{2} -x_{3} \\right)^{2}\\left(f \\left(x_{2} \\right)-f \\left(x_{1} \\right) \\right)}{ \\left(x_{2} -x_{1} \\right) \\left(f \\left(x_{2} \\right)-f \\left(x_{3} \\right)\\right)- \\left(x_{2} -x_{3} \\right) \\left(f \\left(x_{2} \\right)-f \\left(x_{1} \\right) \\right)}$$\n", "\n", "Where $x_{4}$ location of the maximum or minimum of the parabola. " ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 23, "metadata": { "collapsed": false }, @@ -1418,7 +1449,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 24, "metadata": { "collapsed": false }, @@ -1628,7 +1659,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 25, "metadata": { "collapsed": false }, @@ -1851,12 +1882,14 @@ "\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$" + "$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": 24, + "execution_count": 26, "metadata": { "collapsed": false }, @@ -1865,6 +1898,11 @@ "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" ] @@ -2037,7 +2075,7 @@ "\n", "%[Emin,imin]=min(Ex);\n", "\n", - "[xmin,Emin] = fminbnd(@(x) lennard_jones(x,sigma,epsilon),0.28,0.6)\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", @@ -2048,168 +2086,11 @@ }, { "cell_type": "code", - "execution_count": 114, + "execution_count": 31, "metadata": { "collapsed": false }, "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", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n", - "warning: Matlab-style short-circuit operation performed for operator |\n" - ] - }, { "data": { "image/svg+xml": [ @@ -2289,30 +2170,45 @@ "\n", "\n", "\t\t\n", - "\t\t-0.01\n", + "\t\t0\n", "\t\n", "\n", "\n", - "\t\t\n", - "\t\t0\n", + "\t\t\n", + "\t\t0.005\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0.01\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", + "\t\t0.015\n", + "\t\n", + "\n", + "\n", + "\t\t\n", "\t\t0.02\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", + "\t\t0.025\n", + "\t\n", + "\n", + "\n", + "\t\t\n", "\t\t0.03\n", "\t\n", "\n", "\n", + "\t\t\n", + "\t\t0.035\n", + "\t\n", + "\n", + "\n", "\t\t\n", "\t\t0.04\n", "\t\n", @@ -2337,7 +2233,7 @@ "\n", "\n", "\n", - "\t\n", + "\t\n", "\t\n", "\n", "\n", @@ -2360,6 +2256,7 @@ ], "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", @@ -2376,12 +2273,16 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "For this function, it is possible to take a derivative and compare the analytical result:" + "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": 105, + "execution_count": 32, "metadata": { "collapsed": false }, @@ -2438,68 +2339,73 @@ "\n", "\n", "\t\n", - "\t\t\n", + "\t\t\n", "\t\n", "\n", "\n", "\n", "\n", - "\t\t\n", + "\t\t\n", + "\t\t-0.0005\n", + "\t\n", + "\n", + "\n", + "\t\t\n", "\t\t0\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0.0005\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0.001\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0.0015\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0.002\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0.0025\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0.01\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0.02\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0.03\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0.04\n", "\t\n", "\n", "\n", - "\t\t\n", + "\t\t\n", "\t\t0.05\n", "\t\n", "\n", @@ -2511,18 +2417,18 @@ "\n", "\n", "\n", - "\t\n", + "\t\n", "\n", "\n", "\tgnuplot_plot_1a\n", "\n", "\n", "\n", - "\t\n", + "\t\n", "\t\n", "\tgnuplot_plot_2a\n", "\n", - "\t\n", + "\t\n", "\t\n", "\n", "\n", @@ -2563,7 +2469,7 @@ }, { "cell_type": "code", - "execution_count": 106, + "execution_count": 33, "metadata": { "collapsed": false }, @@ -2582,7 +2488,7 @@ }, { "cell_type": "code", - "execution_count": 113, + "execution_count": 34, "metadata": { "collapsed": false }, @@ -2605,7 +2511,7 @@ }, { "cell_type": "code", - "execution_count": 108, + "execution_count": 35, "metadata": { "collapsed": false }, @@ -2755,7 +2661,7 @@ "\t\n", "\t\n", "\t\n", - "\t\n", + "\t\n", "\t\n", "\t\n", "\t\n", @@ -2797,7 +2703,7 @@ "\t\n", "\tgnuplot_plot_2a\n", "\n", - "\t\n", + "\t\n", "\t\n", "\n", "\n", @@ -2821,6 +2727,15 @@ "source": [ "plot(dx,F_applied,'o',dx,K(1)*dx+1/2*K(2)*dx.^2)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/lecture_08/lecture_08.md b/lecture_08/lecture_08.md index 8a81a2a..79edc0a 100644 --- a/lecture_08/lecture_08.md +++ b/lecture_08/lecture_08.md @@ -19,7 +19,7 @@ Considering a 1-D gold chain, we can calculate the bond length, $x_{b}$, with no Computational Tools to Study and Predict the Long-Term Stability of Nanowires. By Martin E. Zoloff Michoff, Patricio Vélez, Sergio A. Dassie and Ezequiel P. M. Leiva -![Model of Gold chain, from molecular dynamics simulation](Auchain_model.gif) +![Model of Gold chain, from molecular dynamics simulation](Auchain_model.png) [Single atom gold chain mechanics](http://www.uam.es/personal_pdi/ciencias/agrait/) diff --git a/lecture_08/lecture_08.pdf b/lecture_08/lecture_08.pdf new file mode 100644 index 0000000..c251694 Binary files /dev/null and b/lecture_08/lecture_08.pdf differ diff --git a/lecture_08/octave-workspace b/lecture_08/octave-workspace index 990b83a..8c437bb 100644 Binary files a/lecture_08/octave-workspace and b/lecture_08/octave-workspace differ