Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
added optimization lecture
- Loading branch information
Showing
13 changed files
with
5,826 additions
and
179 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
2,836 changes: 2,836 additions & 0 deletions
2,836
08_optimization/.ipynb_checkpoints/lecture_08-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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{:}); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
function E_LJ =lennard_jones(x,sigma,epsilon) | ||
E_LJ = 4*epsilon*((sigma./x).^12-(sigma./x).^6); | ||
end | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
|