Skip to content
Permalink
8821175f2a
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
1941 lines (1941 sloc) 149 KB
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%plot --format svg"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Optimization\n",
"\n",
"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": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"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 \n",
"\n",
"![Model of Gold chain, from molecular dynamics simulation](Auchain_model.gif)\n",
"\n",
"[Single atom gold chain mechanics](http://www.uam.es/personal_pdi/ciencias/agrait/)\n",
"\n",
"### First, let's find the minimum energy $\\min(E_{LJ}(x))$\n",
"\n",
"## Brute force"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg height=\"420px\" viewBox=\"0 0 560 420\" width=\"560px\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"\n",
"<title>Gnuplot</title>\n",
"<desc>Produced by GNUPLOT 5.0 patchlevel 3 </desc>\n",
"\n",
"<g id=\"gnuplot_canvas\">\n",
"\n",
"<rect fill=\"none\" height=\"420\" width=\"560\" x=\"0\" y=\"0\"/>\n",
"<defs>\n",
"\n",
"\t<circle id=\"gpDot\" r=\"0.5\" stroke-width=\"0.5\"/>\n",
"\t<path d=\"M-1,0 h2 M0,-1 v2\" id=\"gpPt0\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<path d=\"M-1,-1 L1,1 M1,-1 L-1,1\" id=\"gpPt1\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<path d=\"M-1,0 L1,0 M0,-1 L0,1 M-1,-1 L1,1 M-1,1 L1,-1\" id=\"gpPt2\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<rect height=\"2\" id=\"gpPt3\" stroke=\"currentColor\" stroke-width=\"0.222\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<rect fill=\"currentColor\" height=\"2\" id=\"gpPt4\" stroke=\"currentColor\" stroke-width=\"0.222\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<circle cx=\"0\" cy=\"0\" id=\"gpPt5\" r=\"1\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt6\" stroke=\"none\" xlink:href=\"#gpPt5\"/>\n",
"\t<path d=\"M0,-1.33 L-1.33,0.67 L1.33,0.67 z\" id=\"gpPt7\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt8\" stroke=\"none\" xlink:href=\"#gpPt7\"/>\n",
"\t<use id=\"gpPt9\" stroke=\"currentColor\" transform=\"rotate(180)\" xlink:href=\"#gpPt7\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt10\" stroke=\"none\" xlink:href=\"#gpPt9\"/>\n",
"\t<use id=\"gpPt11\" stroke=\"currentColor\" transform=\"rotate(45)\" xlink:href=\"#gpPt3\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt12\" stroke=\"none\" xlink:href=\"#gpPt11\"/>\n",
"\t<path d=\"M0,1.330 L1.265,0.411 L0.782,-1.067 L-0.782,-1.076 L-1.265,0.411 z\" id=\"gpPt13\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt14\" stroke=\"none\" xlink:href=\"#gpPt13\"/>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"textbox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"white\" flood-opacity=\"1\" result=\"bgnd\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"bgnd\" operator=\"atop\"/>\n",
"\t</filter>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"greybox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"lightgrey\" flood-opacity=\"1\" result=\"grey\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"grey\" operator=\"atop\"/>\n",
"\t</filter>\n",
"</defs>\n",
"<g color=\"white\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"\t<g shape-rendering=\"crispEdges\" stroke=\"none\">\n",
"\t\t<polygon fill=\"rgb(255, 255, 255)\" points=\"62.2,384.0 534.9,384.0 534.9,16.8 62.2,16.8 \"/>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"rgb(255, 255, 255)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,384.0 L74.7,384.0 M535.0,384.0 L522.5,384.0 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,390.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.04</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,322.8 L74.7,322.8 M535.0,322.8 L522.5,322.8 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,328.8)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.02</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,261.6 L74.7,261.6 M535.0,261.6 L522.5,261.6 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,267.6)\">\n",
"\t\t<text><tspan font-family=\"{}\">0</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,200.3 L74.7,200.3 M535.0,200.3 L522.5,200.3 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,206.3)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.02</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,139.1 L74.7,139.1 M535.0,139.1 L522.5,139.1 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,145.1)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.04</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,77.9 L74.7,77.9 M535.0,77.9 L522.5,77.9 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,83.9)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.06</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,16.7 L74.7,16.7 M535.0,16.7 L522.5,16.7 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,22.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.08</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,384.0 L62.2,371.5 M62.2,16.7 L62.2,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(62.2,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">2.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M129.7,384.0 L129.7,371.5 M129.7,16.7 L129.7,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(129.7,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">3</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M197.3,384.0 L197.3,371.5 M197.3,16.7 L197.3,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(197.3,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">3.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M264.8,384.0 L264.8,371.5 M264.8,16.7 L264.8,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(264.8,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">4</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M332.4,384.0 L332.4,371.5 M332.4,16.7 L332.4,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(332.4,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">4.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M399.9,384.0 L399.9,371.5 M399.9,16.7 L399.9,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(399.9,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M467.5,384.0 L467.5,371.5 M467.5,16.7 L467.5,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(467.5,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">5.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M535.0,384.0 L535.0,371.5 M535.0,16.7 L535.0,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(535.0,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">6</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,16.7 L62.2,384.0 L535.0,384.0 L535.0,16.7 L62.2,16.7 Z \" stroke=\"black\"/></g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"\t<g id=\"gnuplot_plot_1a\"><title>gnuplot_plot_1a</title>\n",
"<g color=\"white\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M102.7,56.9 L104.9,91.1 L107.1,122.2 L109.2,150.4 L111.4,176.0 L113.6,199.2 L115.8,220.2 L117.9,239.1 L120.1,256.2 L122.3,271.7 L124.4,285.6 L126.6,298.1 L128.8,309.3 L131.0,319.3 L133.1,328.2 L135.3,336.1 L137.5,343.2 L139.7,349.4 L141.8,354.9 L144.0,359.7 L146.2,363.8 L148.3,367.4 L150.5,370.4 L152.7,373.0 L154.9,375.2 L157.0,376.9 L159.2,378.3 L161.4,379.4 L163.5,380.1 L165.7,380.6 L167.9,380.9 L170.1,380.9 L172.2,380.8 L174.4,380.4 L176.6,379.9 L178.8,379.3 L180.9,378.5 L183.1,377.6 L185.3,376.6 L187.4,375.5 L189.6,374.4 L191.8,373.1 L194.0,371.9 L196.1,370.5 L198.3,369.1 L200.5,367.7 L202.6,366.2 L204.8,364.7 L207.0,363.2 L209.2,361.7 L211.3,360.1 L213.5,358.5 L215.7,357.0 L217.9,355.4 L220.0,353.8 L222.2,352.3 L224.4,350.7 L226.5,349.2 L228.7,347.6 L230.9,346.1 L233.1,344.6 L235.2,343.1 L237.4,341.6 L239.6,340.1 L241.7,338.6 L243.9,337.2 L246.1,335.8 L248.3,334.4 L250.4,333.0 L252.6,331.6 L254.8,330.3 L257.0,329.0 L259.1,327.7 L261.3,326.4 L263.5,325.1 L265.6,323.9 L267.8,322.7 L270.0,321.5 L272.2,320.3 L274.3,319.1 L276.5,318.0 L278.7,316.9 L280.8,315.8 L283.0,314.7 L285.2,313.7 L287.4,312.7 L289.5,311.7 L291.7,310.7 L293.9,309.7 L296.1,308.7 L298.2,307.8 L300.4,306.9 L302.6,306.0 L304.7,305.1 L306.9,304.3 L309.1,303.4 L311.3,302.6 L313.4,301.8 L315.6,301.0 L317.8,300.2 L319.9,299.5 L322.1,298.7 L324.3,298.0 L326.5,297.3 L328.6,296.6 L330.8,295.9 L333.0,295.2 L335.2,294.6 L337.3,293.9 L339.5,293.3 L341.7,292.7 L343.8,292.1 L346.0,291.5 L348.2,290.9 L350.4,290.4 L352.5,289.8 L354.7,289.3 L356.9,288.8 L359.0,288.2 L361.2,287.7 L363.4,287.2 L365.6,286.7 L367.7,286.3 L369.9,285.8 L372.1,285.3 L374.3,284.9 L376.4,284.5 L378.6,284.0 L380.8,283.6 L382.9,283.2 L385.1,282.8 L387.3,282.4 L389.5,282.0 L391.6,281.6 L393.8,281.3 L396.0,280.9 L398.1,280.5 L400.3,280.2 L402.5,279.9 L404.7,279.5 L406.8,279.2 L409.0,278.9 L411.2,278.6 L413.4,278.3 L415.5,278.0 L417.7,277.7 L419.9,277.4 L422.0,277.1 L424.2,276.8 L426.4,276.5 L428.6,276.3 L430.7,276.0 L432.9,275.8 L435.1,275.5 L437.2,275.3 L439.4,275.0 L441.6,274.8 L443.8,274.6 L445.9,274.3 L448.1,274.1 L450.3,273.9 L452.5,273.7 L454.6,273.5 L456.8,273.3 L459.0,273.1 L461.1,272.9 L463.3,272.7 L465.5,272.5 L467.7,272.3 L469.8,272.1 L472.0,271.9 L474.2,271.8 L476.3,271.6 L478.5,271.4 L480.7,271.3 L482.9,271.1 L485.0,270.9 L487.2,270.8 L489.4,270.6 L491.6,270.5 L493.7,270.3 L495.9,270.2 L498.1,270.0 L500.2,269.9 L502.4,269.8 L504.6,269.6 L506.8,269.5 L508.9,269.4 L511.1,269.3 L513.3,269.1 L515.4,269.0 L517.6,268.9 L519.8,268.8 L522.0,268.7 L524.1,268.5 L526.3,268.4 L528.5,268.3 L530.7,268.2 L532.8,268.1 L535.0,268.0 \" stroke=\"rgb( 0, 0, 255)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_2a\"><title>gnuplot_plot_2a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb( 0, 128, 0)\" transform=\"translate(170.1,380.9) scale(9.00)\" xlink:href=\"#gpPt5\"/></g>\n",
"</g>\n",
"\t</g>\n",
"<g color=\"white\" fill=\"none\" stroke=\"rgb( 0, 128, 0)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"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": 4,
"metadata": {
"collapsed": false
},
"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": {},
"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": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"current_min = -0.019959\r\n"
]
},
{
"data": {
"image/svg+xml": [
"<svg height=\"420px\" viewBox=\"0 0 560 420\" width=\"560px\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"\n",
"<title>Gnuplot</title>\n",
"<desc>Produced by GNUPLOT 5.0 patchlevel 3 </desc>\n",
"\n",
"<g id=\"gnuplot_canvas\">\n",
"\n",
"<rect fill=\"none\" height=\"420\" width=\"560\" x=\"0\" y=\"0\"/>\n",
"<defs>\n",
"\n",
"\t<circle id=\"gpDot\" r=\"0.5\" stroke-width=\"0.5\"/>\n",
"\t<path d=\"M-1,0 h2 M0,-1 v2\" id=\"gpPt0\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<path d=\"M-1,-1 L1,1 M1,-1 L-1,1\" id=\"gpPt1\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<path d=\"M-1,0 L1,0 M0,-1 L0,1 M-1,-1 L1,1 M-1,1 L1,-1\" id=\"gpPt2\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<rect height=\"2\" id=\"gpPt3\" stroke=\"currentColor\" stroke-width=\"0.222\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<rect fill=\"currentColor\" height=\"2\" id=\"gpPt4\" stroke=\"currentColor\" stroke-width=\"0.222\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<circle cx=\"0\" cy=\"0\" id=\"gpPt5\" r=\"1\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt6\" stroke=\"none\" xlink:href=\"#gpPt5\"/>\n",
"\t<path d=\"M0,-1.33 L-1.33,0.67 L1.33,0.67 z\" id=\"gpPt7\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt8\" stroke=\"none\" xlink:href=\"#gpPt7\"/>\n",
"\t<use id=\"gpPt9\" stroke=\"currentColor\" transform=\"rotate(180)\" xlink:href=\"#gpPt7\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt10\" stroke=\"none\" xlink:href=\"#gpPt9\"/>\n",
"\t<use id=\"gpPt11\" stroke=\"currentColor\" transform=\"rotate(45)\" xlink:href=\"#gpPt3\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt12\" stroke=\"none\" xlink:href=\"#gpPt11\"/>\n",
"\t<path d=\"M0,1.330 L1.265,0.411 L0.782,-1.067 L-0.782,-1.076 L-1.265,0.411 z\" id=\"gpPt13\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt14\" stroke=\"none\" xlink:href=\"#gpPt13\"/>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"textbox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"white\" flood-opacity=\"1\" result=\"bgnd\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"bgnd\" operator=\"atop\"/>\n",
"\t</filter>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"greybox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"lightgrey\" flood-opacity=\"1\" result=\"grey\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"grey\" operator=\"atop\"/>\n",
"\t</filter>\n",
"</defs>\n",
"<g color=\"white\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"\t<g shape-rendering=\"crispEdges\" stroke=\"none\">\n",
"\t\t<polygon fill=\"rgb(255, 255, 255)\" points=\"62.2,384.0 534.9,384.0 534.9,16.8 62.2,16.8 \"/>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"rgb(255, 255, 255)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,384.0 L74.7,384.0 M535.0,384.0 L522.5,384.0 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,390.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.04</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,322.8 L74.7,322.8 M535.0,322.8 L522.5,322.8 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,328.8)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.02</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,261.6 L74.7,261.6 M535.0,261.6 L522.5,261.6 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,267.6)\">\n",
"\t\t<text><tspan font-family=\"{}\">0</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,200.3 L74.7,200.3 M535.0,200.3 L522.5,200.3 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,206.3)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.02</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,139.1 L74.7,139.1 M535.0,139.1 L522.5,139.1 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,145.1)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.04</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,77.9 L74.7,77.9 M535.0,77.9 L522.5,77.9 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,83.9)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.06</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,16.7 L74.7,16.7 M535.0,16.7 L522.5,16.7 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,22.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.08</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,384.0 L62.2,371.5 M62.2,16.7 L62.2,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(62.2,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">2.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M129.7,384.0 L129.7,371.5 M129.7,16.7 L129.7,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(129.7,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">3</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M197.3,384.0 L197.3,371.5 M197.3,16.7 L197.3,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(197.3,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">3.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M264.8,384.0 L264.8,371.5 M264.8,16.7 L264.8,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(264.8,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">4</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M332.4,384.0 L332.4,371.5 M332.4,16.7 L332.4,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(332.4,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">4.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M399.9,384.0 L399.9,371.5 M399.9,16.7 L399.9,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(399.9,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M467.5,384.0 L467.5,371.5 M467.5,16.7 L467.5,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(467.5,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">5.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M535.0,384.0 L535.0,371.5 M535.0,16.7 L535.0,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(535.0,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">6</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,16.7 L62.2,384.0 L535.0,384.0 L535.0,16.7 L62.2,16.7 Z \" stroke=\"black\"/></g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"\t<g id=\"gnuplot_plot_1a\"><title>gnuplot_plot_1a</title>\n",
"<g color=\"white\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M102.7,56.9 L104.9,91.1 L107.1,122.2 L109.2,150.4 L111.4,176.0 L113.6,199.2 L115.8,220.2 L117.9,239.1 L120.1,256.2 L122.3,271.7 L124.4,285.6 L126.6,298.1 L128.8,309.3 L131.0,319.3 L133.1,328.2 L135.3,336.1 L137.5,343.2 L139.7,349.4 L141.8,354.9 L144.0,359.7 L146.2,363.8 L148.3,367.4 L150.5,370.4 L152.7,373.0 L154.9,375.2 L157.0,376.9 L159.2,378.3 L161.4,379.4 L163.5,380.1 L165.7,380.6 L167.9,380.9 L170.1,380.9 L172.2,380.8 L174.4,380.4 L176.6,379.9 L178.8,379.3 L180.9,378.5 L183.1,377.6 L185.3,376.6 L187.4,375.5 L189.6,374.4 L191.8,373.1 L194.0,371.9 L196.1,370.5 L198.3,369.1 L200.5,367.7 L202.6,366.2 L204.8,364.7 L207.0,363.2 L209.2,361.7 L211.3,360.1 L213.5,358.5 L215.7,357.0 L217.9,355.4 L220.0,353.8 L222.2,352.3 L224.4,350.7 L226.5,349.2 L228.7,347.6 L230.9,346.1 L233.1,344.6 L235.2,343.1 L237.4,341.6 L239.6,340.1 L241.7,338.6 L243.9,337.2 L246.1,335.8 L248.3,334.4 L250.4,333.0 L252.6,331.6 L254.8,330.3 L257.0,329.0 L259.1,327.7 L261.3,326.4 L263.5,325.1 L265.6,323.9 L267.8,322.7 L270.0,321.5 L272.2,320.3 L274.3,319.1 L276.5,318.0 L278.7,316.9 L280.8,315.8 L283.0,314.7 L285.2,313.7 L287.4,312.7 L289.5,311.7 L291.7,310.7 L293.9,309.7 L296.1,308.7 L298.2,307.8 L300.4,306.9 L302.6,306.0 L304.7,305.1 L306.9,304.3 L309.1,303.4 L311.3,302.6 L313.4,301.8 L315.6,301.0 L317.8,300.2 L319.9,299.5 L322.1,298.7 L324.3,298.0 L326.5,297.3 L328.6,296.6 L330.8,295.9 L333.0,295.2 L335.2,294.6 L337.3,293.9 L339.5,293.3 L341.7,292.7 L343.8,292.1 L346.0,291.5 L348.2,290.9 L350.4,290.4 L352.5,289.8 L354.7,289.3 L356.9,288.8 L359.0,288.2 L361.2,287.7 L363.4,287.2 L365.6,286.7 L367.7,286.3 L369.9,285.8 L372.1,285.3 L374.3,284.9 L376.4,284.5 L378.6,284.0 L380.8,283.6 L382.9,283.2 L385.1,282.8 L387.3,282.4 L389.5,282.0 L391.6,281.6 L393.8,281.3 L396.0,280.9 L398.1,280.5 L400.3,280.2 L402.5,279.9 L404.7,279.5 L406.8,279.2 L409.0,278.9 L411.2,278.6 L413.4,278.3 L415.5,278.0 L417.7,277.7 L419.9,277.4 L422.0,277.1 L424.2,276.8 L426.4,276.5 L428.6,276.3 L430.7,276.0 L432.9,275.8 L435.1,275.5 L437.2,275.3 L439.4,275.0 L441.6,274.8 L443.8,274.6 L445.9,274.3 L448.1,274.1 L450.3,273.9 L452.5,273.7 L454.6,273.5 L456.8,273.3 L459.0,273.1 L461.1,272.9 L463.3,272.7 L465.5,272.5 L467.7,272.3 L469.8,272.1 L472.0,271.9 L474.2,271.8 L476.3,271.6 L478.5,271.4 L480.7,271.3 L482.9,271.1 L485.0,270.9 L487.2,270.8 L489.4,270.6 L491.6,270.5 L493.7,270.3 L495.9,270.2 L498.1,270.0 L500.2,269.9 L502.4,269.8 L504.6,269.6 L506.8,269.5 L508.9,269.4 L511.1,269.3 L513.3,269.1 L515.4,269.0 L517.6,268.9 L519.8,268.8 L522.0,268.7 L524.1,268.5 L526.3,268.4 L528.5,268.3 L530.7,268.2 L532.8,268.1 L535.0,268.0 \" stroke=\"rgb( 0, 0, 255)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_2a\"><title>gnuplot_plot_2a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(102.7,56.9) scale(9.00)\" xlink:href=\"#gpPt5\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_3a\"><title>gnuplot_plot_3a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(267.8,322.7) scale(9.00)\" xlink:href=\"#gpPt3\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_4a\"><title>gnuplot_plot_4a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb( 0, 255, 0)\" transform=\"translate(369.9,285.8) scale(9.00)\" xlink:href=\"#gpPt3\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_5a\"><title>gnuplot_plot_5a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb( 0, 255, 0)\" transform=\"translate(535.0,268.0) scale(9.00)\" xlink:href=\"#gpPt5\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_6a\"><title>gnuplot_plot_6a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M535.0,268.0 L369.9,285.8 \" stroke=\"rgb( 0, 0, 0)\"/></g>\n",
"\t</g>\n",
"<g color=\"white\" fill=\"none\" stroke=\"rgb( 0, 0, 0)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"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<f1\n",
" plot([x_u,x1],[Au_x(x_u),f1],'k-')\n",
" x_u=x1;\n",
"else \n",
" plot([x_l,x2],[Au_x(x_l),f2],'k-')\n",
" x_l=x1;\n",
"end\n",
"hold off\n",
"%old_min = current_min;\n",
"current_min=min([f1,f2,Au_x(x_l),Au_x(x_u)])\n",
"%error_app=abs((current_min-old_min)/current_min)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"current_min = -0.033707\n",
"error_app = 0.40787\n"
]
},
{
"data": {
"image/svg+xml": [
"<svg height=\"420px\" viewBox=\"0 0 560 420\" width=\"560px\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"\n",
"<title>Gnuplot</title>\n",
"<desc>Produced by GNUPLOT 5.0 patchlevel 3 </desc>\n",
"\n",
"<g id=\"gnuplot_canvas\">\n",
"\n",
"<rect fill=\"none\" height=\"420\" width=\"560\" x=\"0\" y=\"0\"/>\n",
"<defs>\n",
"\n",
"\t<circle id=\"gpDot\" r=\"0.5\" stroke-width=\"0.5\"/>\n",
"\t<path d=\"M-1,0 h2 M0,-1 v2\" id=\"gpPt0\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<path d=\"M-1,-1 L1,1 M1,-1 L-1,1\" id=\"gpPt1\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<path d=\"M-1,0 L1,0 M0,-1 L0,1 M-1,-1 L1,1 M-1,1 L1,-1\" id=\"gpPt2\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<rect height=\"2\" id=\"gpPt3\" stroke=\"currentColor\" stroke-width=\"0.222\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<rect fill=\"currentColor\" height=\"2\" id=\"gpPt4\" stroke=\"currentColor\" stroke-width=\"0.222\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<circle cx=\"0\" cy=\"0\" id=\"gpPt5\" r=\"1\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt6\" stroke=\"none\" xlink:href=\"#gpPt5\"/>\n",
"\t<path d=\"M0,-1.33 L-1.33,0.67 L1.33,0.67 z\" id=\"gpPt7\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt8\" stroke=\"none\" xlink:href=\"#gpPt7\"/>\n",
"\t<use id=\"gpPt9\" stroke=\"currentColor\" transform=\"rotate(180)\" xlink:href=\"#gpPt7\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt10\" stroke=\"none\" xlink:href=\"#gpPt9\"/>\n",
"\t<use id=\"gpPt11\" stroke=\"currentColor\" transform=\"rotate(45)\" xlink:href=\"#gpPt3\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt12\" stroke=\"none\" xlink:href=\"#gpPt11\"/>\n",
"\t<path d=\"M0,1.330 L1.265,0.411 L0.782,-1.067 L-0.782,-1.076 L-1.265,0.411 z\" id=\"gpPt13\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt14\" stroke=\"none\" xlink:href=\"#gpPt13\"/>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"textbox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"white\" flood-opacity=\"1\" result=\"bgnd\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"bgnd\" operator=\"atop\"/>\n",
"\t</filter>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"greybox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"lightgrey\" flood-opacity=\"1\" result=\"grey\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"grey\" operator=\"atop\"/>\n",
"\t</filter>\n",
"</defs>\n",
"<g color=\"white\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"\t<g shape-rendering=\"crispEdges\" stroke=\"none\">\n",
"\t\t<polygon fill=\"rgb(255, 255, 255)\" points=\"62.2,384.0 534.9,384.0 534.9,16.8 62.2,16.8 \"/>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"rgb(255, 255, 255)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,384.0 L74.7,384.0 M535.0,384.0 L522.5,384.0 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,390.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.04</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,322.8 L74.7,322.8 M535.0,322.8 L522.5,322.8 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,328.8)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.02</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,261.6 L74.7,261.6 M535.0,261.6 L522.5,261.6 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,267.6)\">\n",
"\t\t<text><tspan font-family=\"{}\">0</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,200.3 L74.7,200.3 M535.0,200.3 L522.5,200.3 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,206.3)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.02</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,139.1 L74.7,139.1 M535.0,139.1 L522.5,139.1 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,145.1)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.04</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,77.9 L74.7,77.9 M535.0,77.9 L522.5,77.9 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,83.9)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.06</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,16.7 L74.7,16.7 M535.0,16.7 L522.5,16.7 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,22.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.08</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,384.0 L62.2,371.5 M62.2,16.7 L62.2,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(62.2,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">2.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M129.7,384.0 L129.7,371.5 M129.7,16.7 L129.7,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(129.7,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">3</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M197.3,384.0 L197.3,371.5 M197.3,16.7 L197.3,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(197.3,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">3.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M264.8,384.0 L264.8,371.5 M264.8,16.7 L264.8,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(264.8,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">4</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M332.4,384.0 L332.4,371.5 M332.4,16.7 L332.4,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(332.4,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">4.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M399.9,384.0 L399.9,371.5 M399.9,16.7 L399.9,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(399.9,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M467.5,384.0 L467.5,371.5 M467.5,16.7 L467.5,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(467.5,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">5.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M535.0,384.0 L535.0,371.5 M535.0,16.7 L535.0,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(535.0,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">6</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,16.7 L62.2,384.0 L535.0,384.0 L535.0,16.7 L62.2,16.7 Z \" stroke=\"black\"/></g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"\t<g id=\"gnuplot_plot_1a\"><title>gnuplot_plot_1a</title>\n",
"<g color=\"white\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M102.7,56.9 L104.9,91.1 L107.1,122.2 L109.2,150.4 L111.4,176.0 L113.6,199.2 L115.8,220.2 L117.9,239.1 L120.1,256.2 L122.3,271.7 L124.4,285.6 L126.6,298.1 L128.8,309.3 L131.0,319.3 L133.1,328.2 L135.3,336.1 L137.5,343.2 L139.7,349.4 L141.8,354.9 L144.0,359.7 L146.2,363.8 L148.3,367.4 L150.5,370.4 L152.7,373.0 L154.9,375.2 L157.0,376.9 L159.2,378.3 L161.4,379.4 L163.5,380.1 L165.7,380.6 L167.9,380.9 L170.1,380.9 L172.2,380.8 L174.4,380.4 L176.6,379.9 L178.8,379.3 L180.9,378.5 L183.1,377.6 L185.3,376.6 L187.4,375.5 L189.6,374.4 L191.8,373.1 L194.0,371.9 L196.1,370.5 L198.3,369.1 L200.5,367.7 L202.6,366.2 L204.8,364.7 L207.0,363.2 L209.2,361.7 L211.3,360.1 L213.5,358.5 L215.7,357.0 L217.9,355.4 L220.0,353.8 L222.2,352.3 L224.4,350.7 L226.5,349.2 L228.7,347.6 L230.9,346.1 L233.1,344.6 L235.2,343.1 L237.4,341.6 L239.6,340.1 L241.7,338.6 L243.9,337.2 L246.1,335.8 L248.3,334.4 L250.4,333.0 L252.6,331.6 L254.8,330.3 L257.0,329.0 L259.1,327.7 L261.3,326.4 L263.5,325.1 L265.6,323.9 L267.8,322.7 L270.0,321.5 L272.2,320.3 L274.3,319.1 L276.5,318.0 L278.7,316.9 L280.8,315.8 L283.0,314.7 L285.2,313.7 L287.4,312.7 L289.5,311.7 L291.7,310.7 L293.9,309.7 L296.1,308.7 L298.2,307.8 L300.4,306.9 L302.6,306.0 L304.7,305.1 L306.9,304.3 L309.1,303.4 L311.3,302.6 L313.4,301.8 L315.6,301.0 L317.8,300.2 L319.9,299.5 L322.1,298.7 L324.3,298.0 L326.5,297.3 L328.6,296.6 L330.8,295.9 L333.0,295.2 L335.2,294.6 L337.3,293.9 L339.5,293.3 L341.7,292.7 L343.8,292.1 L346.0,291.5 L348.2,290.9 L350.4,290.4 L352.5,289.8 L354.7,289.3 L356.9,288.8 L359.0,288.2 L361.2,287.7 L363.4,287.2 L365.6,286.7 L367.7,286.3 L369.9,285.8 L372.1,285.3 L374.3,284.9 L376.4,284.5 L378.6,284.0 L380.8,283.6 L382.9,283.2 L385.1,282.8 L387.3,282.4 L389.5,282.0 L391.6,281.6 L393.8,281.3 L396.0,280.9 L398.1,280.5 L400.3,280.2 L402.5,279.9 L404.7,279.5 L406.8,279.2 L409.0,278.9 L411.2,278.6 L413.4,278.3 L415.5,278.0 L417.7,277.7 L419.9,277.4 L422.0,277.1 L424.2,276.8 L426.4,276.5 L428.6,276.3 L430.7,276.0 L432.9,275.8 L435.1,275.5 L437.2,275.3 L439.4,275.0 L441.6,274.8 L443.8,274.6 L445.9,274.3 L448.1,274.1 L450.3,273.9 L452.5,273.7 L454.6,273.5 L456.8,273.3 L459.0,273.1 L461.1,272.9 L463.3,272.7 L465.5,272.5 L467.7,272.3 L469.8,272.1 L472.0,271.9 L474.2,271.8 L476.3,271.6 L478.5,271.4 L480.7,271.3 L482.9,271.1 L485.0,270.9 L487.2,270.8 L489.4,270.6 L491.6,270.5 L493.7,270.3 L495.9,270.2 L498.1,270.0 L500.2,269.9 L502.4,269.8 L504.6,269.6 L506.8,269.5 L508.9,269.4 L511.1,269.3 L513.3,269.1 L515.4,269.0 L517.6,268.9 L519.8,268.8 L522.0,268.7 L524.1,268.5 L526.3,268.4 L528.5,268.3 L530.7,268.2 L532.8,268.1 L535.0,268.0 \" stroke=\"rgb( 0, 0, 255)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_2a\"><title>gnuplot_plot_2a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(102.7,56.9) scale(9.00)\" xlink:href=\"#gpPt5\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_3a\"><title>gnuplot_plot_3a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(204.8,364.7) scale(9.00)\" xlink:href=\"#gpPt3\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_4a\"><title>gnuplot_plot_4a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb( 0, 255, 0)\" transform=\"translate(267.8,322.7) scale(9.00)\" xlink:href=\"#gpPt3\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_5a\"><title>gnuplot_plot_5a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb( 0, 255, 0)\" transform=\"translate(369.9,285.8) scale(9.00)\" xlink:href=\"#gpPt5\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_6a\"><title>gnuplot_plot_6a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M369.9,285.8 L267.8,322.7 \" stroke=\"rgb( 0, 0, 0)\"/></g>\n",
"\t</g>\n",
"<g color=\"white\" fill=\"none\" stroke=\"rgb( 0, 0, 0)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"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<f1\n",
" plot([x_u,x1],[Au_x(x_u),f1],'k-')\n",
" x_u=x1;\n",
"else \n",
" plot([x_l,x2],[Au_x(x_l),f2],'k-')\n",
" x_l=x1;\n",
"end\n",
"hold off\n",
"old_min = current_min;\n",
"current_min=min([f1,f2,Au_x(x_l),Au_x(x_u)])\n",
"error_app=abs((current_min-old_min)/current_min)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"current_min = -0.038904\n",
"error_app = 0\n"
]
},
{
"data": {
"image/svg+xml": [
"<svg height=\"420px\" viewBox=\"0 0 560 420\" width=\"560px\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"\n",
"<title>Gnuplot</title>\n",
"<desc>Produced by GNUPLOT 5.0 patchlevel 3 </desc>\n",
"\n",
"<g id=\"gnuplot_canvas\">\n",
"\n",
"<rect fill=\"none\" height=\"420\" width=\"560\" x=\"0\" y=\"0\"/>\n",
"<defs>\n",
"\n",
"\t<circle id=\"gpDot\" r=\"0.5\" stroke-width=\"0.5\"/>\n",
"\t<path d=\"M-1,0 h2 M0,-1 v2\" id=\"gpPt0\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<path d=\"M-1,-1 L1,1 M1,-1 L-1,1\" id=\"gpPt1\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<path d=\"M-1,0 L1,0 M0,-1 L0,1 M-1,-1 L1,1 M-1,1 L1,-1\" id=\"gpPt2\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<rect height=\"2\" id=\"gpPt3\" stroke=\"currentColor\" stroke-width=\"0.222\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<rect fill=\"currentColor\" height=\"2\" id=\"gpPt4\" stroke=\"currentColor\" stroke-width=\"0.222\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<circle cx=\"0\" cy=\"0\" id=\"gpPt5\" r=\"1\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt6\" stroke=\"none\" xlink:href=\"#gpPt5\"/>\n",
"\t<path d=\"M0,-1.33 L-1.33,0.67 L1.33,0.67 z\" id=\"gpPt7\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt8\" stroke=\"none\" xlink:href=\"#gpPt7\"/>\n",
"\t<use id=\"gpPt9\" stroke=\"currentColor\" transform=\"rotate(180)\" xlink:href=\"#gpPt7\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt10\" stroke=\"none\" xlink:href=\"#gpPt9\"/>\n",
"\t<use id=\"gpPt11\" stroke=\"currentColor\" transform=\"rotate(45)\" xlink:href=\"#gpPt3\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt12\" stroke=\"none\" xlink:href=\"#gpPt11\"/>\n",
"\t<path d=\"M0,1.330 L1.265,0.411 L0.782,-1.067 L-0.782,-1.076 L-1.265,0.411 z\" id=\"gpPt13\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt14\" stroke=\"none\" xlink:href=\"#gpPt13\"/>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"textbox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"white\" flood-opacity=\"1\" result=\"bgnd\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"bgnd\" operator=\"atop\"/>\n",
"\t</filter>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"greybox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"lightgrey\" flood-opacity=\"1\" result=\"grey\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"grey\" operator=\"atop\"/>\n",
"\t</filter>\n",
"</defs>\n",
"<g color=\"white\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"\t<g shape-rendering=\"crispEdges\" stroke=\"none\">\n",
"\t\t<polygon fill=\"rgb(255, 255, 255)\" points=\"62.2,384.0 534.9,384.0 534.9,16.8 62.2,16.8 \"/>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"rgb(255, 255, 255)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,384.0 L74.7,384.0 M535.0,384.0 L522.5,384.0 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,390.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.04</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,322.8 L74.7,322.8 M535.0,322.8 L522.5,322.8 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,328.8)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.02</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,261.6 L74.7,261.6 M535.0,261.6 L522.5,261.6 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,267.6)\">\n",
"\t\t<text><tspan font-family=\"{}\">0</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,200.3 L74.7,200.3 M535.0,200.3 L522.5,200.3 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,206.3)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.02</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,139.1 L74.7,139.1 M535.0,139.1 L522.5,139.1 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,145.1)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.04</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,77.9 L74.7,77.9 M535.0,77.9 L522.5,77.9 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,83.9)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.06</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,16.7 L74.7,16.7 M535.0,16.7 L522.5,16.7 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,22.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.08</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,384.0 L62.2,371.5 M62.2,16.7 L62.2,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(62.2,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">2.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M129.7,384.0 L129.7,371.5 M129.7,16.7 L129.7,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(129.7,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">3</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M197.3,384.0 L197.3,371.5 M197.3,16.7 L197.3,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(197.3,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">3.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M264.8,384.0 L264.8,371.5 M264.8,16.7 L264.8,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(264.8,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">4</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M332.4,384.0 L332.4,371.5 M332.4,16.7 L332.4,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(332.4,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">4.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M399.9,384.0 L399.9,371.5 M399.9,16.7 L399.9,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(399.9,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M467.5,384.0 L467.5,371.5 M467.5,16.7 L467.5,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(467.5,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">5.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M535.0,384.0 L535.0,371.5 M535.0,16.7 L535.0,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(535.0,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">6</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,16.7 L62.2,384.0 L535.0,384.0 L535.0,16.7 L62.2,16.7 Z \" stroke=\"black\"/></g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"\t<g id=\"gnuplot_plot_1a\"><title>gnuplot_plot_1a</title>\n",
"<g color=\"white\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M102.7,56.9 L104.9,91.1 L107.1,122.2 L109.2,150.4 L111.4,176.0 L113.6,199.2 L115.8,220.2 L117.9,239.1 L120.1,256.2 L122.3,271.7 L124.4,285.6 L126.6,298.1 L128.8,309.3 L131.0,319.3 L133.1,328.2 L135.3,336.1 L137.5,343.2 L139.7,349.4 L141.8,354.9 L144.0,359.7 L146.2,363.8 L148.3,367.4 L150.5,370.4 L152.7,373.0 L154.9,375.2 L157.0,376.9 L159.2,378.3 L161.4,379.4 L163.5,380.1 L165.7,380.6 L167.9,380.9 L170.1,380.9 L172.2,380.8 L174.4,380.4 L176.6,379.9 L178.8,379.3 L180.9,378.5 L183.1,377.6 L185.3,376.6 L187.4,375.5 L189.6,374.4 L191.8,373.1 L194.0,371.9 L196.1,370.5 L198.3,369.1 L200.5,367.7 L202.6,366.2 L204.8,364.7 L207.0,363.2 L209.2,361.7 L211.3,360.1 L213.5,358.5 L215.7,357.0 L217.9,355.4 L220.0,353.8 L222.2,352.3 L224.4,350.7 L226.5,349.2 L228.7,347.6 L230.9,346.1 L233.1,344.6 L235.2,343.1 L237.4,341.6 L239.6,340.1 L241.7,338.6 L243.9,337.2 L246.1,335.8 L248.3,334.4 L250.4,333.0 L252.6,331.6 L254.8,330.3 L257.0,329.0 L259.1,327.7 L261.3,326.4 L263.5,325.1 L265.6,323.9 L267.8,322.7 L270.0,321.5 L272.2,320.3 L274.3,319.1 L276.5,318.0 L278.7,316.9 L280.8,315.8 L283.0,314.7 L285.2,313.7 L287.4,312.7 L289.5,311.7 L291.7,310.7 L293.9,309.7 L296.1,308.7 L298.2,307.8 L300.4,306.9 L302.6,306.0 L304.7,305.1 L306.9,304.3 L309.1,303.4 L311.3,302.6 L313.4,301.8 L315.6,301.0 L317.8,300.2 L319.9,299.5 L322.1,298.7 L324.3,298.0 L326.5,297.3 L328.6,296.6 L330.8,295.9 L333.0,295.2 L335.2,294.6 L337.3,293.9 L339.5,293.3 L341.7,292.7 L343.8,292.1 L346.0,291.5 L348.2,290.9 L350.4,290.4 L352.5,289.8 L354.7,289.3 L356.9,288.8 L359.0,288.2 L361.2,287.7 L363.4,287.2 L365.6,286.7 L367.7,286.3 L369.9,285.8 L372.1,285.3 L374.3,284.9 L376.4,284.5 L378.6,284.0 L380.8,283.6 L382.9,283.2 L385.1,282.8 L387.3,282.4 L389.5,282.0 L391.6,281.6 L393.8,281.3 L396.0,280.9 L398.1,280.5 L400.3,280.2 L402.5,279.9 L404.7,279.5 L406.8,279.2 L409.0,278.9 L411.2,278.6 L413.4,278.3 L415.5,278.0 L417.7,277.7 L419.9,277.4 L422.0,277.1 L424.2,276.8 L426.4,276.5 L428.6,276.3 L430.7,276.0 L432.9,275.8 L435.1,275.5 L437.2,275.3 L439.4,275.0 L441.6,274.8 L443.8,274.6 L445.9,274.3 L448.1,274.1 L450.3,273.9 L452.5,273.7 L454.6,273.5 L456.8,273.3 L459.0,273.1 L461.1,272.9 L463.3,272.7 L465.5,272.5 L467.7,272.3 L469.8,272.1 L472.0,271.9 L474.2,271.8 L476.3,271.6 L478.5,271.4 L480.7,271.3 L482.9,271.1 L485.0,270.9 L487.2,270.8 L489.4,270.6 L491.6,270.5 L493.7,270.3 L495.9,270.2 L498.1,270.0 L500.2,269.9 L502.4,269.8 L504.6,269.6 L506.8,269.5 L508.9,269.4 L511.1,269.3 L513.3,269.1 L515.4,269.0 L517.6,268.9 L519.8,268.8 L522.0,268.7 L524.1,268.5 L526.3,268.4 L528.5,268.3 L530.7,268.2 L532.8,268.1 L535.0,268.0 \" stroke=\"rgb( 0, 0, 255)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_2a\"><title>gnuplot_plot_2a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(165.8,380.6) scale(9.00)\" xlink:href=\"#gpPt5\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_3a\"><title>gnuplot_plot_3a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(175.0,380.3) scale(9.00)\" xlink:href=\"#gpPt3\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_4a\"><title>gnuplot_plot_4a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb( 0, 255, 0)\" transform=\"translate(180.7,378.6) scale(9.00)\" xlink:href=\"#gpPt3\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_5a\"><title>gnuplot_plot_5a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb( 0, 255, 0)\" transform=\"translate(189.9,374.2) scale(9.00)\" xlink:href=\"#gpPt5\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_6a\"><title>gnuplot_plot_6a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M189.9,374.2 L180.7,378.6 \" stroke=\"rgb( 0, 0, 0)\"/></g>\n",
"\t</g>\n",
"<g color=\"white\" fill=\"none\" stroke=\"rgb( 0, 0, 0)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"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<f1\n",
" plot([x_u,x1],[Au_x(x_u),f1],'k-')\n",
" x_u=x1;\n",
"else \n",
" plot([x_l,x2],[Au_x(x_l),f2],'k-')\n",
" x_l=x1;\n",
"end\n",
"hold off\n",
"old_min = current_min;\n",
"current_min=min([f1,f2,Au_x(x_l),Au_x(x_u)])\n",
"error_app=abs((current_min-old_min)/current_min)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"current_min = -0.039000\n",
"error_app = 0\n"
]
},
{
"data": {
"image/svg+xml": [
"<svg height=\"420px\" viewBox=\"0 0 560 420\" width=\"560px\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"\n",
"<title>Gnuplot</title>\n",
"<desc>Produced by GNUPLOT 5.0 patchlevel 3 </desc>\n",
"\n",
"<g id=\"gnuplot_canvas\">\n",
"\n",
"<rect fill=\"none\" height=\"420\" width=\"560\" x=\"0\" y=\"0\"/>\n",
"<defs>\n",
"\n",
"\t<circle id=\"gpDot\" r=\"0.5\" stroke-width=\"0.5\"/>\n",
"\t<path d=\"M-1,0 h2 M0,-1 v2\" id=\"gpPt0\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<path d=\"M-1,-1 L1,1 M1,-1 L-1,1\" id=\"gpPt1\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<path d=\"M-1,0 L1,0 M0,-1 L0,1 M-1,-1 L1,1 M-1,1 L1,-1\" id=\"gpPt2\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<rect height=\"2\" id=\"gpPt3\" stroke=\"currentColor\" stroke-width=\"0.222\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<rect fill=\"currentColor\" height=\"2\" id=\"gpPt4\" stroke=\"currentColor\" stroke-width=\"0.222\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<circle cx=\"0\" cy=\"0\" id=\"gpPt5\" r=\"1\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt6\" stroke=\"none\" xlink:href=\"#gpPt5\"/>\n",
"\t<path d=\"M0,-1.33 L-1.33,0.67 L1.33,0.67 z\" id=\"gpPt7\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt8\" stroke=\"none\" xlink:href=\"#gpPt7\"/>\n",
"\t<use id=\"gpPt9\" stroke=\"currentColor\" transform=\"rotate(180)\" xlink:href=\"#gpPt7\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt10\" stroke=\"none\" xlink:href=\"#gpPt9\"/>\n",
"\t<use id=\"gpPt11\" stroke=\"currentColor\" transform=\"rotate(45)\" xlink:href=\"#gpPt3\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt12\" stroke=\"none\" xlink:href=\"#gpPt11\"/>\n",
"\t<path d=\"M0,1.330 L1.265,0.411 L0.782,-1.067 L-0.782,-1.076 L-1.265,0.411 z\" id=\"gpPt13\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt14\" stroke=\"none\" xlink:href=\"#gpPt13\"/>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"textbox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"white\" flood-opacity=\"1\" result=\"bgnd\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"bgnd\" operator=\"atop\"/>\n",
"\t</filter>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"greybox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"lightgrey\" flood-opacity=\"1\" result=\"grey\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"grey\" operator=\"atop\"/>\n",
"\t</filter>\n",
"</defs>\n",
"<g color=\"white\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"\t<g shape-rendering=\"crispEdges\" stroke=\"none\">\n",
"\t\t<polygon fill=\"rgb(255, 255, 255)\" points=\"62.2,384.0 534.9,384.0 534.9,16.8 62.2,16.8 \"/>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"rgb(255, 255, 255)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,384.0 L74.7,384.0 M535.0,384.0 L522.5,384.0 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,390.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.04</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,322.8 L74.7,322.8 M535.0,322.8 L522.5,322.8 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,328.8)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.02</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,261.6 L74.7,261.6 M535.0,261.6 L522.5,261.6 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,267.6)\">\n",
"\t\t<text><tspan font-family=\"{}\">0</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,200.3 L74.7,200.3 M535.0,200.3 L522.5,200.3 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,206.3)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.02</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,139.1 L74.7,139.1 M535.0,139.1 L522.5,139.1 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,145.1)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.04</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,77.9 L74.7,77.9 M535.0,77.9 L522.5,77.9 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,83.9)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.06</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,16.7 L74.7,16.7 M535.0,16.7 L522.5,16.7 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,22.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.08</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,384.0 L62.2,371.5 M62.2,16.7 L62.2,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(62.2,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">2.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M129.7,384.0 L129.7,371.5 M129.7,16.7 L129.7,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(129.7,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">3</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M197.3,384.0 L197.3,371.5 M197.3,16.7 L197.3,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(197.3,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">3.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M264.8,384.0 L264.8,371.5 M264.8,16.7 L264.8,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(264.8,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">4</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M332.4,384.0 L332.4,371.5 M332.4,16.7 L332.4,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(332.4,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">4.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M399.9,384.0 L399.9,371.5 M399.9,16.7 L399.9,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(399.9,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M467.5,384.0 L467.5,371.5 M467.5,16.7 L467.5,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(467.5,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">5.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M535.0,384.0 L535.0,371.5 M535.0,16.7 L535.0,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(535.0,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">6</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,16.7 L62.2,384.0 L535.0,384.0 L535.0,16.7 L62.2,16.7 Z \" stroke=\"black\"/></g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"\t<g id=\"gnuplot_plot_1a\"><title>gnuplot_plot_1a</title>\n",
"<g color=\"white\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M102.7,56.9 L104.9,91.1 L107.1,122.2 L109.2,150.4 L111.4,176.0 L113.6,199.2 L115.8,220.2 L117.9,239.1 L120.1,256.2 L122.3,271.7 L124.4,285.6 L126.6,298.1 L128.8,309.3 L131.0,319.3 L133.1,328.2 L135.3,336.1 L137.5,343.2 L139.7,349.4 L141.8,354.9 L144.0,359.7 L146.2,363.8 L148.3,367.4 L150.5,370.4 L152.7,373.0 L154.9,375.2 L157.0,376.9 L159.2,378.3 L161.4,379.4 L163.5,380.1 L165.7,380.6 L167.9,380.9 L170.1,380.9 L172.2,380.8 L174.4,380.4 L176.6,379.9 L178.8,379.3 L180.9,378.5 L183.1,377.6 L185.3,376.6 L187.4,375.5 L189.6,374.4 L191.8,373.1 L194.0,371.9 L196.1,370.5 L198.3,369.1 L200.5,367.7 L202.6,366.2 L204.8,364.7 L207.0,363.2 L209.2,361.7 L211.3,360.1 L213.5,358.5 L215.7,357.0 L217.9,355.4 L220.0,353.8 L222.2,352.3 L224.4,350.7 L226.5,349.2 L228.7,347.6 L230.9,346.1 L233.1,344.6 L235.2,343.1 L237.4,341.6 L239.6,340.1 L241.7,338.6 L243.9,337.2 L246.1,335.8 L248.3,334.4 L250.4,333.0 L252.6,331.6 L254.8,330.3 L257.0,329.0 L259.1,327.7 L261.3,326.4 L263.5,325.1 L265.6,323.9 L267.8,322.7 L270.0,321.5 L272.2,320.3 L274.3,319.1 L276.5,318.0 L278.7,316.9 L280.8,315.8 L283.0,314.7 L285.2,313.7 L287.4,312.7 L289.5,311.7 L291.7,310.7 L293.9,309.7 L296.1,308.7 L298.2,307.8 L300.4,306.9 L302.6,306.0 L304.7,305.1 L306.9,304.3 L309.1,303.4 L311.3,302.6 L313.4,301.8 L315.6,301.0 L317.8,300.2 L319.9,299.5 L322.1,298.7 L324.3,298.0 L326.5,297.3 L328.6,296.6 L330.8,295.9 L333.0,295.2 L335.2,294.6 L337.3,293.9 L339.5,293.3 L341.7,292.7 L343.8,292.1 L346.0,291.5 L348.2,290.9 L350.4,290.4 L352.5,289.8 L354.7,289.3 L356.9,288.8 L359.0,288.2 L361.2,287.7 L363.4,287.2 L365.6,286.7 L367.7,286.3 L369.9,285.8 L372.1,285.3 L374.3,284.9 L376.4,284.5 L378.6,284.0 L380.8,283.6 L382.9,283.2 L385.1,282.8 L387.3,282.4 L389.5,282.0 L391.6,281.6 L393.8,281.3 L396.0,280.9 L398.1,280.5 L400.3,280.2 L402.5,279.9 L404.7,279.5 L406.8,279.2 L409.0,278.9 L411.2,278.6 L413.4,278.3 L415.5,278.0 L417.7,277.7 L419.9,277.4 L422.0,277.1 L424.2,276.8 L426.4,276.5 L428.6,276.3 L430.7,276.0 L432.9,275.8 L435.1,275.5 L437.2,275.3 L439.4,275.0 L441.6,274.8 L443.8,274.6 L445.9,274.3 L448.1,274.1 L450.3,273.9 L452.5,273.7 L454.6,273.5 L456.8,273.3 L459.0,273.1 L461.1,272.9 L463.3,272.7 L465.5,272.5 L467.7,272.3 L469.8,272.1 L472.0,271.9 L474.2,271.8 L476.3,271.6 L478.5,271.4 L480.7,271.3 L482.9,271.1 L485.0,270.9 L487.2,270.8 L489.4,270.6 L491.6,270.5 L493.7,270.3 L495.9,270.2 L498.1,270.0 L500.2,269.9 L502.4,269.8 L504.6,269.6 L506.8,269.5 L508.9,269.4 L511.1,269.3 L513.3,269.1 L515.4,269.0 L517.6,268.9 L519.8,268.8 L522.0,268.7 L524.1,268.5 L526.3,268.4 L528.5,268.3 L530.7,268.2 L532.8,268.1 L535.0,268.0 \" stroke=\"rgb( 0, 0, 255)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_2a\"><title>gnuplot_plot_2a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(165.8,380.6) scale(9.00)\" xlink:href=\"#gpPt5\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_3a\"><title>gnuplot_plot_3a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(168.0,380.9) scale(9.00)\" xlink:href=\"#gpPt3\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_4a\"><title>gnuplot_plot_4a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb( 0, 255, 0)\" transform=\"translate(169.3,380.9) scale(9.00)\" xlink:href=\"#gpPt3\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_5a\"><title>gnuplot_plot_5a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb( 0, 255, 0)\" transform=\"translate(171.5,380.8) scale(9.00)\" xlink:href=\"#gpPt5\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_6a\"><title>gnuplot_plot_6a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M165.8,380.6 L168.0,380.9 \" stroke=\"rgb( 0, 0, 0)\"/></g>\n",
"\t</g>\n",
"<g color=\"white\" fill=\"none\" stroke=\"rgb( 0, 0, 0)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"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<f1\n",
" plot([x_u,x1],[Au_x(x_u),f1],'k-')\n",
" x_u=x1;\n",
"else \n",
" plot([x_l,x2],[Au_x(x_l),f2],'k-')\n",
" x_l=x1;\n",
"end\n",
"hold off\n",
"old_min = current_min;\n",
"current_min=min([f1,f2,Au_x(x_l),Au_x(x_u)])\n",
"error_app=abs((current_min-old_min)/current_min)"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"## Parabolc Interpolation\n",
"\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",
"\n",
"Where $x_{4}$ location of the maximum or minimum of the parabola. "
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg height=\"420px\" viewBox=\"0 0 560 420\" width=\"560px\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"\n",
"<title>Gnuplot</title>\n",
"<desc>Produced by GNUPLOT 5.0 patchlevel 3 </desc>\n",
"\n",
"<g id=\"gnuplot_canvas\">\n",
"\n",
"<rect fill=\"none\" height=\"420\" width=\"560\" x=\"0\" y=\"0\"/>\n",
"<defs>\n",
"\n",
"\t<circle id=\"gpDot\" r=\"0.5\" stroke-width=\"0.5\"/>\n",
"\t<path d=\"M-1,0 h2 M0,-1 v2\" id=\"gpPt0\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<path d=\"M-1,-1 L1,1 M1,-1 L-1,1\" id=\"gpPt1\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<path d=\"M-1,0 L1,0 M0,-1 L0,1 M-1,-1 L1,1 M-1,1 L1,-1\" id=\"gpPt2\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<rect height=\"2\" id=\"gpPt3\" stroke=\"currentColor\" stroke-width=\"0.222\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<rect fill=\"currentColor\" height=\"2\" id=\"gpPt4\" stroke=\"currentColor\" stroke-width=\"0.222\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<circle cx=\"0\" cy=\"0\" id=\"gpPt5\" r=\"1\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt6\" stroke=\"none\" xlink:href=\"#gpPt5\"/>\n",
"\t<path d=\"M0,-1.33 L-1.33,0.67 L1.33,0.67 z\" id=\"gpPt7\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt8\" stroke=\"none\" xlink:href=\"#gpPt7\"/>\n",
"\t<use id=\"gpPt9\" stroke=\"currentColor\" transform=\"rotate(180)\" xlink:href=\"#gpPt7\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt10\" stroke=\"none\" xlink:href=\"#gpPt9\"/>\n",
"\t<use id=\"gpPt11\" stroke=\"currentColor\" transform=\"rotate(45)\" xlink:href=\"#gpPt3\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt12\" stroke=\"none\" xlink:href=\"#gpPt11\"/>\n",
"\t<path d=\"M0,1.330 L1.265,0.411 L0.782,-1.067 L-0.782,-1.076 L-1.265,0.411 z\" id=\"gpPt13\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt14\" stroke=\"none\" xlink:href=\"#gpPt13\"/>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"textbox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"white\" flood-opacity=\"1\" result=\"bgnd\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"bgnd\" operator=\"atop\"/>\n",
"\t</filter>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"greybox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"lightgrey\" flood-opacity=\"1\" result=\"grey\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"grey\" operator=\"atop\"/>\n",
"\t</filter>\n",
"</defs>\n",
"<g color=\"white\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"\t<g shape-rendering=\"crispEdges\" stroke=\"none\">\n",
"\t\t<polygon fill=\"rgb(255, 255, 255)\" points=\"62.2,384.0 534.9,384.0 534.9,16.8 62.2,16.8 \"/>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"rgb(255, 255, 255)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,384.0 L74.7,384.0 M535.0,384.0 L522.5,384.0 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,390.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.06</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,331.5 L74.7,331.5 M535.0,331.5 L522.5,331.5 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,337.5)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.04</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,279.1 L74.7,279.1 M535.0,279.1 L522.5,279.1 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,285.1)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.02</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,226.6 L74.7,226.6 M535.0,226.6 L522.5,226.6 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,232.6)\">\n",
"\t\t<text><tspan font-family=\"{}\">0</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,174.1 L74.7,174.1 M535.0,174.1 L522.5,174.1 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,180.1)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.02</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,121.6 L74.7,121.6 M535.0,121.6 L522.5,121.6 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,127.6)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.04</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,69.2 L74.7,69.2 M535.0,69.2 L522.5,69.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,75.2)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.06</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,16.7 L74.7,16.7 M535.0,16.7 L522.5,16.7 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,22.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.08</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,384.0 L62.2,371.5 M62.2,16.7 L62.2,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(62.2,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">2.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M129.7,384.0 L129.7,371.5 M129.7,16.7 L129.7,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(129.7,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">3</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M197.3,384.0 L197.3,371.5 M197.3,16.7 L197.3,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(197.3,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">3.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M264.8,384.0 L264.8,371.5 M264.8,16.7 L264.8,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(264.8,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">4</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M332.4,384.0 L332.4,371.5 M332.4,16.7 L332.4,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(332.4,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">4.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M399.9,384.0 L399.9,371.5 M399.9,16.7 L399.9,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(399.9,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M467.5,384.0 L467.5,371.5 M467.5,16.7 L467.5,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(467.5,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">5.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M535.0,384.0 L535.0,371.5 M535.0,16.7 L535.0,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(535.0,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">6</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,16.7 L62.2,384.0 L535.0,384.0 L535.0,16.7 L62.2,16.7 Z \" stroke=\"black\"/></g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"\t<g id=\"gnuplot_plot_1a\"><title>gnuplot_plot_1a</title>\n",
"<g color=\"white\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M102.7,51.2 L104.9,80.5 L107.1,107.1 L109.2,131.3 L111.4,153.2 L113.6,173.1 L115.8,191.1 L117.9,207.3 L120.1,222.0 L122.3,235.3 L124.4,247.2 L126.6,257.9 L128.8,267.5 L131.0,276.0 L133.1,283.7 L135.3,290.5 L137.5,296.5 L139.7,301.9 L141.8,306.6 L144.0,310.7 L146.2,314.2 L148.3,317.3 L150.5,319.9 L152.7,322.1 L154.9,324.0 L157.0,325.5 L159.2,326.6 L161.4,327.6 L163.5,328.2 L165.7,328.6 L167.9,328.9 L170.1,328.9 L172.2,328.8 L174.4,328.5 L176.6,328.0 L178.8,327.5 L180.9,326.8 L183.1,326.1 L185.3,325.2 L187.4,324.3 L189.6,323.3 L191.8,322.2 L194.0,321.1 L196.1,320.0 L198.3,318.8 L200.5,317.5 L202.6,316.3 L204.8,315.0 L207.0,313.7 L209.2,312.4 L211.3,311.0 L213.5,309.7 L215.7,308.4 L217.9,307.0 L220.0,305.7 L222.2,304.3 L224.4,303.0 L226.5,301.7 L228.7,300.3 L230.9,299.0 L233.1,297.7 L235.2,296.4 L237.4,295.2 L239.6,293.9 L241.7,292.7 L243.9,291.4 L246.1,290.2 L248.3,289.0 L250.4,287.8 L252.6,286.6 L254.8,285.5 L257.0,284.4 L259.1,283.2 L261.3,282.1 L263.5,281.1 L265.6,280.0 L267.8,279.0 L270.0,277.9 L272.2,276.9 L274.3,275.9 L276.5,275.0 L278.7,274.0 L280.8,273.1 L283.0,272.2 L285.2,271.3 L287.4,270.4 L289.5,269.5 L291.7,268.7 L293.9,267.8 L296.1,267.0 L298.2,266.2 L300.4,265.4 L302.6,264.7 L304.7,263.9 L306.9,263.2 L309.1,262.5 L311.3,261.8 L313.4,261.1 L315.6,260.4 L317.8,259.7 L319.9,259.1 L322.1,258.4 L324.3,257.8 L326.5,257.2 L328.6,256.6 L330.8,256.0 L333.0,255.5 L335.2,254.9 L337.3,254.3 L339.5,253.8 L341.7,253.3 L343.8,252.8 L346.0,252.3 L348.2,251.8 L350.4,251.3 L352.5,250.8 L354.7,250.3 L356.9,249.9 L359.0,249.4 L361.2,249.0 L363.4,248.6 L365.6,248.2 L367.7,247.8 L369.9,247.4 L372.1,247.0 L374.3,246.6 L376.4,246.2 L378.6,245.8 L380.8,245.5 L382.9,245.1 L385.1,244.8 L387.3,244.4 L389.5,244.1 L391.6,243.8 L393.8,243.5 L396.0,243.2 L398.1,242.9 L400.3,242.6 L402.5,242.3 L404.7,242.0 L406.8,241.7 L409.0,241.4 L411.2,241.2 L413.4,240.9 L415.5,240.6 L417.7,240.4 L419.9,240.1 L422.0,239.9 L424.2,239.7 L426.4,239.4 L428.6,239.2 L430.7,239.0 L432.9,238.8 L435.1,238.5 L437.2,238.3 L439.4,238.1 L441.6,237.9 L443.8,237.7 L445.9,237.5 L448.1,237.3 L450.3,237.2 L452.5,237.0 L454.6,236.8 L456.8,236.6 L459.0,236.4 L461.1,236.3 L463.3,236.1 L465.5,235.9 L467.7,235.8 L469.8,235.6 L472.0,235.5 L474.2,235.3 L476.3,235.2 L478.5,235.0 L480.7,234.9 L482.9,234.8 L485.0,234.6 L487.2,234.5 L489.4,234.4 L491.6,234.2 L493.7,234.1 L495.9,234.0 L498.1,233.9 L500.2,233.7 L502.4,233.6 L504.6,233.5 L506.8,233.4 L508.9,233.3 L511.1,233.2 L513.3,233.1 L515.4,233.0 L517.6,232.9 L519.8,232.8 L522.0,232.7 L524.1,232.6 L526.3,232.5 L528.5,232.4 L530.7,232.3 L532.8,232.2 L535.0,232.1 \" stroke=\"rgb( 0, 0, 255)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_2a\"><title>gnuplot_plot_2a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M102.7,51.2 L107.7,92.0 L112.7,129.9 L117.7,164.8 L122.6,196.8 L127.6,225.7 L132.6,251.7 L137.6,274.8 L142.5,294.8 L147.5,311.9 L152.5,326.0 L157.5,337.2 L162.4,345.3 L167.4,350.5 L172.4,352.8 L177.4,352.0 L182.4,348.3 L187.3,341.6 L192.3,332.0 L197.3,319.3 \" stroke=\"rgb( 0, 128, 0)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_3a\"><title>gnuplot_plot_3a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(102.7,51.2) scale(9.00)\" xlink:href=\"#gpPt5\"/></g>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(150.0,319.3) scale(9.00)\" xlink:href=\"#gpPt5\"/>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(197.3,319.3) scale(9.00)\" xlink:href=\"#gpPt5\"/>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_4a\"><title>gnuplot_plot_4a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb( 0, 0, 255)\" transform=\"translate(173.6,328.6) scale(9.00)\" xlink:href=\"#gpPt2\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_5a\"><title>gnuplot_plot_5a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M102.7,51.2 L150.0,319.3 \" stroke=\"rgb(191, 0, 191)\"/></g>\n",
"\t</g>\n",
"<g color=\"white\" fill=\"none\" stroke=\"rgb(191, 0, 191)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"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 f2<f1 && f2<f3\n",
" x4=x2-0.5*((x2-x1)^2*(f2-f3)-(x2-x3)^2*(f2-f1))/((x2-x1)...\n",
" *(f2-f3)-(x2-x3)*(f2-f1));\n",
" f4=Au_x(x4);\n",
"\n",
" if x4>x2\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": 32,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"f3 = -0.038878\r\n"
]
},
{
"data": {
"image/svg+xml": [
"<svg height=\"420px\" viewBox=\"0 0 560 420\" width=\"560px\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"\n",
"<title>Gnuplot</title>\n",
"<desc>Produced by GNUPLOT 5.0 patchlevel 3 </desc>\n",
"\n",
"<g id=\"gnuplot_canvas\">\n",
"\n",
"<rect fill=\"none\" height=\"420\" width=\"560\" x=\"0\" y=\"0\"/>\n",
"<defs>\n",
"\n",
"\t<circle id=\"gpDot\" r=\"0.5\" stroke-width=\"0.5\"/>\n",
"\t<path d=\"M-1,0 h2 M0,-1 v2\" id=\"gpPt0\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<path d=\"M-1,-1 L1,1 M1,-1 L-1,1\" id=\"gpPt1\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<path d=\"M-1,0 L1,0 M0,-1 L0,1 M-1,-1 L1,1 M-1,1 L1,-1\" id=\"gpPt2\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<rect height=\"2\" id=\"gpPt3\" stroke=\"currentColor\" stroke-width=\"0.222\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<rect fill=\"currentColor\" height=\"2\" id=\"gpPt4\" stroke=\"currentColor\" stroke-width=\"0.222\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<circle cx=\"0\" cy=\"0\" id=\"gpPt5\" r=\"1\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt6\" stroke=\"none\" xlink:href=\"#gpPt5\"/>\n",
"\t<path d=\"M0,-1.33 L-1.33,0.67 L1.33,0.67 z\" id=\"gpPt7\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt8\" stroke=\"none\" xlink:href=\"#gpPt7\"/>\n",
"\t<use id=\"gpPt9\" stroke=\"currentColor\" transform=\"rotate(180)\" xlink:href=\"#gpPt7\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt10\" stroke=\"none\" xlink:href=\"#gpPt9\"/>\n",
"\t<use id=\"gpPt11\" stroke=\"currentColor\" transform=\"rotate(45)\" xlink:href=\"#gpPt3\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt12\" stroke=\"none\" xlink:href=\"#gpPt11\"/>\n",
"\t<path d=\"M0,1.330 L1.265,0.411 L0.782,-1.067 L-0.782,-1.076 L-1.265,0.411 z\" id=\"gpPt13\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt14\" stroke=\"none\" xlink:href=\"#gpPt13\"/>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"textbox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"white\" flood-opacity=\"1\" result=\"bgnd\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"bgnd\" operator=\"atop\"/>\n",
"\t</filter>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"greybox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"lightgrey\" flood-opacity=\"1\" result=\"grey\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"grey\" operator=\"atop\"/>\n",
"\t</filter>\n",
"</defs>\n",
"<g color=\"white\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"\t<g shape-rendering=\"crispEdges\" stroke=\"none\">\n",
"\t\t<polygon fill=\"rgb(255, 255, 255)\" points=\"62.2,384.0 534.9,384.0 534.9,16.8 62.2,16.8 \"/>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"rgb(255, 255, 255)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,384.0 L74.7,384.0 M535.0,384.0 L522.5,384.0 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,390.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.04</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,322.8 L74.7,322.8 M535.0,322.8 L522.5,322.8 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,328.8)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.02</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,261.6 L74.7,261.6 M535.0,261.6 L522.5,261.6 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,267.6)\">\n",
"\t\t<text><tspan font-family=\"{}\">0</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,200.3 L74.7,200.3 M535.0,200.3 L522.5,200.3 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,206.3)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.02</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,139.1 L74.7,139.1 M535.0,139.1 L522.5,139.1 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,145.1)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.04</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,77.9 L74.7,77.9 M535.0,77.9 L522.5,77.9 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,83.9)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.06</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,16.7 L74.7,16.7 M535.0,16.7 L522.5,16.7 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,22.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.08</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,384.0 L62.2,371.5 M62.2,16.7 L62.2,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(62.2,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">2.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M129.7,384.0 L129.7,371.5 M129.7,16.7 L129.7,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(129.7,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">3</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M197.3,384.0 L197.3,371.5 M197.3,16.7 L197.3,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(197.3,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">3.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M264.8,384.0 L264.8,371.5 M264.8,16.7 L264.8,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(264.8,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">4</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M332.4,384.0 L332.4,371.5 M332.4,16.7 L332.4,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(332.4,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">4.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M399.9,384.0 L399.9,371.5 M399.9,16.7 L399.9,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(399.9,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M467.5,384.0 L467.5,371.5 M467.5,16.7 L467.5,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(467.5,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">5.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M535.0,384.0 L535.0,371.5 M535.0,16.7 L535.0,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(535.0,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">6</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,16.7 L62.2,384.0 L535.0,384.0 L535.0,16.7 L62.2,16.7 Z \" stroke=\"black\"/></g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"\t<g id=\"gnuplot_plot_1a\"><title>gnuplot_plot_1a</title>\n",
"<g color=\"white\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M102.7,56.9 L104.9,91.1 L107.1,122.2 L109.2,150.4 L111.4,176.0 L113.6,199.2 L115.8,220.2 L117.9,239.1 L120.1,256.2 L122.3,271.7 L124.4,285.6 L126.6,298.1 L128.8,309.3 L131.0,319.3 L133.1,328.2 L135.3,336.1 L137.5,343.2 L139.7,349.4 L141.8,354.9 L144.0,359.7 L146.2,363.8 L148.3,367.4 L150.5,370.4 L152.7,373.0 L154.9,375.2 L157.0,376.9 L159.2,378.3 L161.4,379.4 L163.5,380.1 L165.7,380.6 L167.9,380.9 L170.1,380.9 L172.2,380.8 L174.4,380.4 L176.6,379.9 L178.8,379.3 L180.9,378.5 L183.1,377.6 L185.3,376.6 L187.4,375.5 L189.6,374.4 L191.8,373.1 L194.0,371.9 L196.1,370.5 L198.3,369.1 L200.5,367.7 L202.6,366.2 L204.8,364.7 L207.0,363.2 L209.2,361.7 L211.3,360.1 L213.5,358.5 L215.7,357.0 L217.9,355.4 L220.0,353.8 L222.2,352.3 L224.4,350.7 L226.5,349.2 L228.7,347.6 L230.9,346.1 L233.1,344.6 L235.2,343.1 L237.4,341.6 L239.6,340.1 L241.7,338.6 L243.9,337.2 L246.1,335.8 L248.3,334.4 L250.4,333.0 L252.6,331.6 L254.8,330.3 L257.0,329.0 L259.1,327.7 L261.3,326.4 L263.5,325.1 L265.6,323.9 L267.8,322.7 L270.0,321.5 L272.2,320.3 L274.3,319.1 L276.5,318.0 L278.7,316.9 L280.8,315.8 L283.0,314.7 L285.2,313.7 L287.4,312.7 L289.5,311.7 L291.7,310.7 L293.9,309.7 L296.1,308.7 L298.2,307.8 L300.4,306.9 L302.6,306.0 L304.7,305.1 L306.9,304.3 L309.1,303.4 L311.3,302.6 L313.4,301.8 L315.6,301.0 L317.8,300.2 L319.9,299.5 L322.1,298.7 L324.3,298.0 L326.5,297.3 L328.6,296.6 L330.8,295.9 L333.0,295.2 L335.2,294.6 L337.3,293.9 L339.5,293.3 L341.7,292.7 L343.8,292.1 L346.0,291.5 L348.2,290.9 L350.4,290.4 L352.5,289.8 L354.7,289.3 L356.9,288.8 L359.0,288.2 L361.2,287.7 L363.4,287.2 L365.6,286.7 L367.7,286.3 L369.9,285.8 L372.1,285.3 L374.3,284.9 L376.4,284.5 L378.6,284.0 L380.8,283.6 L382.9,283.2 L385.1,282.8 L387.3,282.4 L389.5,282.0 L391.6,281.6 L393.8,281.3 L396.0,280.9 L398.1,280.5 L400.3,280.2 L402.5,279.9 L404.7,279.5 L406.8,279.2 L409.0,278.9 L411.2,278.6 L413.4,278.3 L415.5,278.0 L417.7,277.7 L419.9,277.4 L422.0,277.1 L424.2,276.8 L426.4,276.5 L428.6,276.3 L430.7,276.0 L432.9,275.8 L435.1,275.5 L437.2,275.3 L439.4,275.0 L441.6,274.8 L443.8,274.6 L445.9,274.3 L448.1,274.1 L450.3,273.9 L452.5,273.7 L454.6,273.5 L456.8,273.3 L459.0,273.1 L461.1,272.9 L463.3,272.7 L465.5,272.5 L467.7,272.3 L469.8,272.1 L472.0,271.9 L474.2,271.8 L476.3,271.6 L478.5,271.4 L480.7,271.3 L482.9,271.1 L485.0,270.9 L487.2,270.8 L489.4,270.6 L491.6,270.5 L493.7,270.3 L495.9,270.2 L498.1,270.0 L500.2,269.9 L502.4,269.8 L504.6,269.6 L506.8,269.5 L508.9,269.4 L511.1,269.3 L513.3,269.1 L515.4,269.0 L517.6,268.9 L519.8,268.8 L522.0,268.7 L524.1,268.5 L526.3,268.4 L528.5,268.3 L530.7,268.2 L532.8,268.1 L535.0,268.0 \" stroke=\"rgb( 0, 0, 255)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_2a\"><title>gnuplot_plot_2a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M150.0,369.8 L152.5,371.9 L155.0,373.8 L157.5,375.5 L160.0,376.9 L162.4,378.1 L164.9,379.1 L167.4,379.8 L169.9,380.3 L172.4,380.5 L174.9,380.5 L177.4,380.3 L179.9,379.8 L182.4,379.1 L184.8,378.1 L187.3,376.9 L189.8,375.5 L192.3,373.8 L194.8,371.9 L197.3,369.8 \" stroke=\"rgb( 0, 128, 0)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_3a\"><title>gnuplot_plot_3a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(150.0,369.8) scale(9.00)\" xlink:href=\"#gpPt5\"/></g>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(173.6,380.6) scale(9.00)\" xlink:href=\"#gpPt5\"/>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(197.3,369.8) scale(9.00)\" xlink:href=\"#gpPt5\"/>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_4a\"><title>gnuplot_plot_4a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb( 0, 0, 255)\" transform=\"translate(173.6,380.6) scale(9.00)\" xlink:href=\"#gpPt2\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_5a\"><title>gnuplot_plot_5a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M197.3,369.8 L173.6,380.6 \" stroke=\"rgb(191, 0, 191)\"/></g>\n",
"\t</g>\n",
"<g color=\"white\" fill=\"none\" stroke=\"rgb(191, 0, 191)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"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 f2<f1 && f2<f3\n",
" x4=x2-0.5*((x2-x1)^2*(f2-f3)-(x2-x3)^2*(f2-f1))/((x2-x1)...\n",
" *(f2-f3)-(x2-x3)*(f2-f1));\n",
" f4=Au_x(x4);\n",
"\n",
" if x4>x2\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": 33,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"f3 = -0.038878\r\n"
]
},
{
"data": {
"image/svg+xml": [
"<svg height=\"420px\" viewBox=\"0 0 560 420\" width=\"560px\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"\n",
"<title>Gnuplot</title>\n",
"<desc>Produced by GNUPLOT 5.0 patchlevel 3 </desc>\n",
"\n",
"<g id=\"gnuplot_canvas\">\n",
"\n",
"<rect fill=\"none\" height=\"420\" width=\"560\" x=\"0\" y=\"0\"/>\n",
"<defs>\n",
"\n",
"\t<circle id=\"gpDot\" r=\"0.5\" stroke-width=\"0.5\"/>\n",
"\t<path d=\"M-1,0 h2 M0,-1 v2\" id=\"gpPt0\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<path d=\"M-1,-1 L1,1 M1,-1 L-1,1\" id=\"gpPt1\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<path d=\"M-1,0 L1,0 M0,-1 L0,1 M-1,-1 L1,1 M-1,1 L1,-1\" id=\"gpPt2\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<rect height=\"2\" id=\"gpPt3\" stroke=\"currentColor\" stroke-width=\"0.222\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<rect fill=\"currentColor\" height=\"2\" id=\"gpPt4\" stroke=\"currentColor\" stroke-width=\"0.222\" width=\"2\" x=\"-1\" y=\"-1\"/>\n",
"\t<circle cx=\"0\" cy=\"0\" id=\"gpPt5\" r=\"1\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt6\" stroke=\"none\" xlink:href=\"#gpPt5\"/>\n",
"\t<path d=\"M0,-1.33 L-1.33,0.67 L1.33,0.67 z\" id=\"gpPt7\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt8\" stroke=\"none\" xlink:href=\"#gpPt7\"/>\n",
"\t<use id=\"gpPt9\" stroke=\"currentColor\" transform=\"rotate(180)\" xlink:href=\"#gpPt7\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt10\" stroke=\"none\" xlink:href=\"#gpPt9\"/>\n",
"\t<use id=\"gpPt11\" stroke=\"currentColor\" transform=\"rotate(45)\" xlink:href=\"#gpPt3\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt12\" stroke=\"none\" xlink:href=\"#gpPt11\"/>\n",
"\t<path d=\"M0,1.330 L1.265,0.411 L0.782,-1.067 L-0.782,-1.076 L-1.265,0.411 z\" id=\"gpPt13\" stroke=\"currentColor\" stroke-width=\"0.222\"/>\n",
"\t<use fill=\"currentColor\" id=\"gpPt14\" stroke=\"none\" xlink:href=\"#gpPt13\"/>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"textbox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"white\" flood-opacity=\"1\" result=\"bgnd\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"bgnd\" operator=\"atop\"/>\n",
"\t</filter>\n",
"\t<filter filterUnits=\"objectBoundingBox\" height=\"1\" id=\"greybox\" width=\"1\" x=\"0\" y=\"0\">\n",
"\t <feFlood flood-color=\"lightgrey\" flood-opacity=\"1\" result=\"grey\"/>\n",
"\t <feComposite in=\"SourceGraphic\" in2=\"grey\" operator=\"atop\"/>\n",
"\t</filter>\n",
"</defs>\n",
"<g color=\"white\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"1.00\">\n",
"\t<g shape-rendering=\"crispEdges\" stroke=\"none\">\n",
"\t\t<polygon fill=\"rgb(255, 255, 255)\" points=\"62.2,384.0 534.9,384.0 534.9,16.8 62.2,16.8 \"/>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"rgb(255, 255, 255)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,384.0 L74.7,384.0 M535.0,384.0 L522.5,384.0 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,390.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.04</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,322.8 L74.7,322.8 M535.0,322.8 L522.5,322.8 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,328.8)\">\n",
"\t\t<text><tspan font-family=\"{}\">-0.02</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,261.6 L74.7,261.6 M535.0,261.6 L522.5,261.6 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,267.6)\">\n",
"\t\t<text><tspan font-family=\"{}\">0</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,200.3 L74.7,200.3 M535.0,200.3 L522.5,200.3 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,206.3)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.02</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,139.1 L74.7,139.1 M535.0,139.1 L522.5,139.1 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,145.1)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.04</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,77.9 L74.7,77.9 M535.0,77.9 L522.5,77.9 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,83.9)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.06</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,16.7 L74.7,16.7 M535.0,16.7 L522.5,16.7 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(53.9,22.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">0.08</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,384.0 L62.2,371.5 M62.2,16.7 L62.2,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(62.2,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">2.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M129.7,384.0 L129.7,371.5 M129.7,16.7 L129.7,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(129.7,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">3</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M197.3,384.0 L197.3,371.5 M197.3,16.7 L197.3,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(197.3,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">3.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M264.8,384.0 L264.8,371.5 M264.8,16.7 L264.8,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(264.8,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">4</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M332.4,384.0 L332.4,371.5 M332.4,16.7 L332.4,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(332.4,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">4.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M399.9,384.0 L399.9,371.5 M399.9,16.7 L399.9,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(399.9,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M467.5,384.0 L467.5,371.5 M467.5,16.7 L467.5,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(467.5,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">5.5</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M535.0,384.0 L535.0,371.5 M535.0,16.7 L535.0,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(535.0,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">6</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M62.2,16.7 L62.2,384.0 L535.0,384.0 L535.0,16.7 L62.2,16.7 Z \" stroke=\"black\"/></g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"\t<g id=\"gnuplot_plot_1a\"><title>gnuplot_plot_1a</title>\n",
"<g color=\"white\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M102.7,56.9 L104.9,91.1 L107.1,122.2 L109.2,150.4 L111.4,176.0 L113.6,199.2 L115.8,220.2 L117.9,239.1 L120.1,256.2 L122.3,271.7 L124.4,285.6 L126.6,298.1 L128.8,309.3 L131.0,319.3 L133.1,328.2 L135.3,336.1 L137.5,343.2 L139.7,349.4 L141.8,354.9 L144.0,359.7 L146.2,363.8 L148.3,367.4 L150.5,370.4 L152.7,373.0 L154.9,375.2 L157.0,376.9 L159.2,378.3 L161.4,379.4 L163.5,380.1 L165.7,380.6 L167.9,380.9 L170.1,380.9 L172.2,380.8 L174.4,380.4 L176.6,379.9 L178.8,379.3 L180.9,378.5 L183.1,377.6 L185.3,376.6 L187.4,375.5 L189.6,374.4 L191.8,373.1 L194.0,371.9 L196.1,370.5 L198.3,369.1 L200.5,367.7 L202.6,366.2 L204.8,364.7 L207.0,363.2 L209.2,361.7 L211.3,360.1 L213.5,358.5 L215.7,357.0 L217.9,355.4 L220.0,353.8 L222.2,352.3 L224.4,350.7 L226.5,349.2 L228.7,347.6 L230.9,346.1 L233.1,344.6 L235.2,343.1 L237.4,341.6 L239.6,340.1 L241.7,338.6 L243.9,337.2 L246.1,335.8 L248.3,334.4 L250.4,333.0 L252.6,331.6 L254.8,330.3 L257.0,329.0 L259.1,327.7 L261.3,326.4 L263.5,325.1 L265.6,323.9 L267.8,322.7 L270.0,321.5 L272.2,320.3 L274.3,319.1 L276.5,318.0 L278.7,316.9 L280.8,315.8 L283.0,314.7 L285.2,313.7 L287.4,312.7 L289.5,311.7 L291.7,310.7 L293.9,309.7 L296.1,308.7 L298.2,307.8 L300.4,306.9 L302.6,306.0 L304.7,305.1 L306.9,304.3 L309.1,303.4 L311.3,302.6 L313.4,301.8 L315.6,301.0 L317.8,300.2 L319.9,299.5 L322.1,298.7 L324.3,298.0 L326.5,297.3 L328.6,296.6 L330.8,295.9 L333.0,295.2 L335.2,294.6 L337.3,293.9 L339.5,293.3 L341.7,292.7 L343.8,292.1 L346.0,291.5 L348.2,290.9 L350.4,290.4 L352.5,289.8 L354.7,289.3 L356.9,288.8 L359.0,288.2 L361.2,287.7 L363.4,287.2 L365.6,286.7 L367.7,286.3 L369.9,285.8 L372.1,285.3 L374.3,284.9 L376.4,284.5 L378.6,284.0 L380.8,283.6 L382.9,283.2 L385.1,282.8 L387.3,282.4 L389.5,282.0 L391.6,281.6 L393.8,281.3 L396.0,280.9 L398.1,280.5 L400.3,280.2 L402.5,279.9 L404.7,279.5 L406.8,279.2 L409.0,278.9 L411.2,278.6 L413.4,278.3 L415.5,278.0 L417.7,277.7 L419.9,277.4 L422.0,277.1 L424.2,276.8 L426.4,276.5 L428.6,276.3 L430.7,276.0 L432.9,275.8 L435.1,275.5 L437.2,275.3 L439.4,275.0 L441.6,274.8 L443.8,274.6 L445.9,274.3 L448.1,274.1 L450.3,273.9 L452.5,273.7 L454.6,273.5 L456.8,273.3 L459.0,273.1 L461.1,272.9 L463.3,272.7 L465.5,272.5 L467.7,272.3 L469.8,272.1 L472.0,271.9 L474.2,271.8 L476.3,271.6 L478.5,271.4 L480.7,271.3 L482.9,271.1 L485.0,270.9 L487.2,270.8 L489.4,270.6 L491.6,270.5 L493.7,270.3 L495.9,270.2 L498.1,270.0 L500.2,269.9 L502.4,269.8 L504.6,269.6 L506.8,269.5 L508.9,269.4 L511.1,269.3 L513.3,269.1 L515.4,269.0 L517.6,268.9 L519.8,268.8 L522.0,268.7 L524.1,268.5 L526.3,268.4 L528.5,268.3 L530.7,268.2 L532.8,268.1 L535.0,268.0 \" stroke=\"rgb( 0, 0, 255)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_2a\"><title>gnuplot_plot_2a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M150.0,369.8 L151.2,371.1 L152.5,372.3 L153.7,373.4 L155.0,374.5 L156.2,375.5 L157.5,376.4 L158.7,377.2 L160.0,377.9 L161.2,378.6 L162.4,379.1 L163.7,379.6 L164.9,380.0 L166.2,380.3 L167.4,380.6 L168.7,380.7 L169.9,380.8 L171.2,380.8 L172.4,380.7 L173.6,380.6 \" stroke=\"rgb( 0, 128, 0)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_3a\"><title>gnuplot_plot_3a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(150.0,369.8) scale(9.00)\" xlink:href=\"#gpPt5\"/></g>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(173.6,380.6) scale(9.00)\" xlink:href=\"#gpPt5\"/>\n",
"\t<use color=\"rgb(255, 0, 0)\" transform=\"translate(173.6,380.6) scale(9.00)\" xlink:href=\"#gpPt5\"/>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_4a\"><title>gnuplot_plot_4a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g onmousemove=\"gnuplot_svg.showHypertext(evt,'')\" onmouseout=\"gnuplot_svg.hideHypertext()\"><title> </title>\n",
"\t<use color=\"rgb( 0, 0, 255)\" transform=\"translate(170.5,380.9) scale(9.00)\" xlink:href=\"#gpPt2\"/></g>\n",
"</g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_5a\"><title>gnuplot_plot_5a</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M173.6,380.6 \" stroke=\"rgb(191, 0, 191)\"/></g>\n",
"\t</g>\n",
"<g color=\"white\" fill=\"none\" stroke=\"rgb(191, 0, 191)\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"2.00\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"black\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"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 f2<f1 && f2<f3\n",
" x4=x2-0.5*((x2-x1)^2*(f2-f3)-(x2-x3)^2*(f2-f1))/((x2-x1)...\n",
" *(f2-f3)-(x2-x3)*(f2-f1));\n",
" f4=Au_x(x4);\n",
"\n",
" if x4>x2\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": {},
"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": {},
"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$"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"xmin = 3.2933\r\n"
]
}
],
"source": [
"xmin = fminbnd(Au_x,2.8,6)\n",
"\n",
"Etotal = @(dx,F) Au_x(xmin+dx)-F.*dx;\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"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
}