Skip to content
Permalink
master
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
{
"cells": [
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%plot --format svg"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"setdefaults"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Roots: Open methods\n",
"## Newton-Raphson"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First-order approximation for the location of the root (i.e. assume the slope at the given point is constant, what is the solution when f(x)=0)\n",
"\n",
"$f'(x_{i})=\\frac{f(x_{i})-0}{x_{i}-x_{i+1}}$\n",
"\n",
"$x_{i+1}=x_{i}-\\frac{f(x_{i})}{f'(x_{i})}$\n",
"\n",
"Use Newton-Raphson to find solution when $e^{-x}=x$"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"x_r = 0.50000\n",
"error_approx = 1\n"
]
}
],
"source": [
"f= @(x) exp(-x)-x;\n",
"df= @(x) -exp(-x)-1;\n",
"\n",
"x_i= 0;\n",
"x_r = x_i-f(x_i)/df(x_i)\n",
"error_approx = abs((x_r-x_i)/x_r)\n",
"x_i=x_r;\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"x_r = 0.56631\n",
"error_approx = 0.11709\n"
]
}
],
"source": [
"x_r = x_i-f(x_i)/df(x_i)\n",
"error_approx = abs((x_r-x_i)/x_r)\n",
"x_i=x_r;"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"x_r = 0.56714\n",
"error_approx = 0.0014673\n"
]
}
],
"source": [
"x_r = x_i-f(x_i)/df(x_i)\n",
"error_approx = abs((x_r-x_i)/x_r)\n",
"x_i=x_r;"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"x_r = 0.56714\n",
"error_approx = 2.2106e-07\n"
]
}
],
"source": [
"x_r = x_i-f(x_i)/df(x_i)\n",
"error_approx = abs((x_r-x_i)/x_r)\n",
"x_i=x_r;"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the bungee jumper example, we created a function f(m) that when f(m)=0, then the mass had been chosen such that at t=4 s, the velocity is 36 m/s. \n",
"\n",
"$f(m)=\\sqrt{\\frac{gm}{c_{d}}}\\tanh(\\sqrt{\\frac{gc_{d}}{m}}t)-v(t)$.\n",
"\n",
"to use the Newton-Raphson method, we need the derivative $\\frac{df}{dm}$\n",
"\n",
"$\\frac{df}{dm}=\\frac{1}{2}\\sqrt{\\frac{g}{mc_{d}}}\\tanh(\\sqrt{\\frac{gc_{d}}{m}}t)-\n",
"\\frac{g}{2m}\\mathrm{sech}^{2}(\\sqrt{\\frac{gc_{d}}{m}}t)$"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"setdefaults\n",
"g=9.81; % acceleration due to gravity\n",
"m=linspace(50, 200,100); % possible values for mass 50 to 200 kg\n",
"c_d=0.25; % drag coefficient\n",
"t=4; % at time = 4 seconds\n",
"v=36; % speed must be 36 m/s\n",
"f_m = @(m) sqrt(g*m/c_d).*tanh(sqrt(g*c_d./m)*t)-v; % anonymous function f_m\n",
"df_m = @(m) 1/2*sqrt(g./m/c_d).*tanh(sqrt(g*c_d./m)*t)-g/2./m*sech(sqrt(g*c_d./m)*t).^2;"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"root = 142.74\n",
"ea = 8.0930e-06\n",
"iter = 48\n"
]
}
],
"source": [
"[root,ea,iter]=newtraph(f_m,df_m,140,0.00001)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Secant Methods"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Not always able to evaluate the derivative. Approximation of derivative:\n",
"\n",
"$f'(x_{i})=\\frac{f(x_{i-1})-f(x_{i})}{x_{i-1}-x_{i}}$\n",
"\n",
"$x_{i+1}=x_{i}-\\frac{f(x_{i})}{f'(x_{i})}$\n",
"\n",
"$x_{i+1}=x_{i}-\\frac{f(x_{i})}{\\frac{f(x_{i-1})-f(x_{i})}{x_{i-1}-x_{i}}}=\n",
" x_{i}-\\frac{f(x_{i})(x_{i-1}-x_{i})}{f(x_{i-1})-f(x_{i})}$\n",
" \n",
"What values should $x_{i}$ and $x_{i-1}$ take?\n",
"\n",
"To reduce arbitrary selection of variables, use the\n",
"\n",
"## Modified Secant method\n",
"\n",
"Change the x evaluations to a perturbation $\\delta$. \n",
"\n",
"$x_{i+1}=x_{i}-\\frac{f(x_{i})(\\delta x_{i})}{f(x_{i}+\\delta x_{i})-f(x_{i})}$"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"root = 142.74\n",
"ea = 3.0615e-07\n",
"iter = 7\n"
]
}
],
"source": [
"[root,ea,iter]=mod_secant(f_m,1,50,0.00001)"
]
},
{
"cell_type": "raw",
"metadata": {},
"source": []
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ans = 1.1185e+04\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=\"80.2,362.4 534.9,362.4 534.9,16.8 80.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=\"M80.2,362.4 L92.7,362.4 M535.0,362.4 L522.5,362.4 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(71.9,368.4)\">\n",
"\t\t<text><tspan font-family=\"{}\">10000</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=\"M80.2,276.0 L92.7,276.0 M535.0,276.0 L522.5,276.0 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(71.9,282.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">15000</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=\"M80.2,189.5 L92.7,189.5 M535.0,189.5 L522.5,189.5 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(71.9,195.5)\">\n",
"\t\t<text><tspan font-family=\"{}\">20000</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=\"M80.2,103.1 L92.7,103.1 M535.0,103.1 L522.5,103.1 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(71.9,109.1)\">\n",
"\t\t<text><tspan font-family=\"{}\">25000</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=\"M80.2,16.7 L92.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(71.9,22.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">30000</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=\"M80.2,362.4 L80.2,349.9 M80.2,16.7 L80.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(80.2,386.4)\">\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=\"M171.2,362.4 L171.2,349.9 M171.2,16.7 L171.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(171.2,386.4)\">\n",
"\t\t<text><tspan font-family=\"{}\">1</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=\"M262.1,362.4 L262.1,349.9 M262.1,16.7 L262.1,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(262.1,386.4)\">\n",
"\t\t<text><tspan font-family=\"{}\">2</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=\"M353.1,362.4 L353.1,349.9 M353.1,16.7 L353.1,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(353.1,386.4)\">\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=\"M444.0,362.4 L444.0,349.9 M444.0,16.7 L444.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(444.0,386.4)\">\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=\"M535.0,362.4 L535.0,349.9 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,386.4)\">\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",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"0.50\">\n",
"\t<path d=\"M80.2,16.7 L80.2,362.4 L535.0,362.4 L535.0,16.7 L80.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",
"\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(19.1,189.6) rotate(-90)\">\n",
"\t\t<text><tspan font-family=\"{}\">principle amount left ($)</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<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(307.6,413.4)\">\n",
"\t\t<text><tspan font-family=\"{}\">time (years)</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",
"\t<g id=\"gnuplot_plot_1a\"><title>gnuplot_plot_1a</title>\n",
"<g color=\"white\" fill=\"none\" stroke=\"currentColor\" 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=\"M87.8,21.5 L95.4,26.3 L102.9,31.1 L110.5,35.9 L118.1,40.8 L125.7,45.7 L133.3,50.6 L140.8,55.5 L148.4,60.5 L156.0,65.4 L163.6,70.4 L171.2,75.4 L178.7,80.4 L186.3,85.5 L193.9,90.6 L201.5,95.7 L209.1,100.8 L216.6,105.9 L224.2,111.1 L231.8,116.2 L239.4,121.4 L247.0,126.6 L254.5,131.9 L262.1,137.1 L269.7,142.4 L277.3,147.7 L284.9,153.1 L292.4,158.4 L300.0,163.8 L307.6,169.2 L315.2,174.6 L322.8,180.0 L330.3,185.5 L337.9,191.0 L345.5,196.5 L353.1,202.0 L360.7,207.6 L368.2,213.2 L375.8,218.8 L383.4,224.4 L391.0,230.0 L398.6,235.7 L406.1,241.4 L413.7,247.1 L421.3,252.9 L428.9,258.6 L436.5,264.4 L444.0,270.2 L451.6,276.1 L459.2,281.9 L466.8,287.8 L474.4,293.7 L481.9,299.7 L489.5,305.6 L497.1,311.6 L504.7,317.6 L512.3,323.7 L519.8,329.7 L527.4,335.8 L535.0,341.9 \" stroke=\"rgb( 0, 0, 255)\"/></g>\n",
"\t</g>\n",
"<g color=\"white\" fill=\"none\" stroke=\"rgb( 0, 0, 255)\" 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": [
"car_payments(400,30000,0.05,5,1)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Amt_numerical = 5467.0\n",
"ans = 3.9755e-04\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=\"88.5,362.4 534.9,362.4 534.9,16.8 88.5,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=\"M88.5,362.4 L101.0,362.4 M535.0,362.4 L522.5,362.4 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(80.2,368.4)\">\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=\"M88.5,313.0 L101.0,313.0 M535.0,313.0 L522.5,313.0 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(80.2,319.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">100000</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=\"M88.5,263.6 L101.0,263.6 M535.0,263.6 L522.5,263.6 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(80.2,269.6)\">\n",
"\t\t<text><tspan font-family=\"{}\">200000</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=\"M88.5,214.2 L101.0,214.2 M535.0,214.2 L522.5,214.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(80.2,220.2)\">\n",
"\t\t<text><tspan font-family=\"{}\">300000</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=\"M88.5,164.9 L101.0,164.9 M535.0,164.9 L522.5,164.9 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(80.2,170.9)\">\n",
"\t\t<text><tspan font-family=\"{}\">400000</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=\"M88.5,115.5 L101.0,115.5 M535.0,115.5 L522.5,115.5 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(80.2,121.5)\">\n",
"\t\t<text><tspan font-family=\"{}\">500000</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=\"M88.5,66.1 L101.0,66.1 M535.0,66.1 L522.5,66.1 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(80.2,72.1)\">\n",
"\t\t<text><tspan font-family=\"{}\">600000</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=\"M88.5,16.7 L101.0,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(80.2,22.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">700000</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=\"M88.5,362.4 L88.5,349.9 M88.5,16.7 L88.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(88.5,386.4)\">\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=\"M162.9,362.4 L162.9,349.9 M162.9,16.7 L162.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(162.9,386.4)\">\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=\"M237.3,362.4 L237.3,349.9 M237.3,16.7 L237.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(237.3,386.4)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</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=\"M311.8,362.4 L311.8,349.9 M311.8,16.7 L311.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(311.8,386.4)\">\n",
"\t\t<text><tspan font-family=\"{}\">15</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=\"M386.2,362.4 L386.2,349.9 M386.2,16.7 L386.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(386.2,386.4)\">\n",
"\t\t<text><tspan font-family=\"{}\">20</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=\"M460.6,362.4 L460.6,349.9 M460.6,16.7 L460.6,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(460.6,386.4)\">\n",
"\t\t<text><tspan font-family=\"{}\">25</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,362.4 L535.0,349.9 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,386.4)\">\n",
"\t\t<text><tspan font-family=\"{}\">30</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=\"M88.5,16.7 L88.5,362.4 L535.0,362.4 L535.0,16.7 L88.5,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",
"\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(19.1,189.6) rotate(-90)\">\n",
"\t\t<text><tspan font-family=\"{}\">principle amount left ($)</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<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(311.7,413.4)\">\n",
"\t\t<text><tspan font-family=\"{}\">time (years)</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",
"\t<g id=\"gnuplot_plot_1a\"><title>gnuplot_plot_1a</title>\n",
"<g color=\"white\" fill=\"none\" stroke=\"currentColor\" 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=\"M89.7,16.9 L91.0,17.1 L92.2,17.3 L93.5,17.5 L94.7,17.7 L95.9,17.9 L97.2,18.1 L98.4,18.3 L99.7,18.5 L100.9,18.8 L102.1,19.0 L103.4,19.2 L104.6,19.4 L105.9,19.6 L107.1,19.8 L108.3,20.1 L109.6,20.3 L110.8,20.5 L112.1,20.7 L113.3,21.0 L114.5,21.2 L115.8,21.4 L117.0,21.7 L118.3,21.9 L119.5,22.1 L120.7,22.4 L122.0,22.6 L123.2,22.9 L124.5,23.1 L125.7,23.3 L126.9,23.6 L128.2,23.8 L129.4,24.1 L130.7,24.3 L131.9,24.6 L133.2,24.9 L134.4,25.1 L135.6,25.4 L136.9,25.6 L138.1,25.9 L139.4,26.2 L140.6,26.4 L141.8,26.7 L143.1,27.0 L144.3,27.2 L145.6,27.5 L146.8,27.8 L148.0,28.1 L149.3,28.4 L150.5,28.6 L151.8,28.9 L153.0,29.2 L154.2,29.5 L155.5,29.8 L156.7,30.1 L158.0,30.4 L159.2,30.7 L160.4,31.0 L161.7,31.3 L162.9,31.6 L164.2,31.9 L165.4,32.2 L166.6,32.5 L167.9,32.8 L169.1,33.2 L170.4,33.5 L171.6,33.8 L172.8,34.1 L174.1,34.5 L175.3,34.8 L176.6,35.1 L177.8,35.4 L179.0,35.8 L180.3,36.1 L181.5,36.5 L182.8,36.8 L184.0,37.1 L185.2,37.5 L186.5,37.8 L187.7,38.2 L189.0,38.6 L190.2,38.9 L191.4,39.3 L192.7,39.6 L193.9,40.0 L195.2,40.4 L196.4,40.7 L197.6,41.1 L198.9,41.5 L200.1,41.9 L201.4,42.3 L202.6,42.6 L203.8,43.0 L205.1,43.4 L206.3,43.8 L207.6,44.2 L208.8,44.6 L210.0,45.0 L211.3,45.4 L212.5,45.8 L213.8,46.2 L215.0,46.7 L216.2,47.1 L217.5,47.5 L218.7,47.9 L220.0,48.3 L221.2,48.8 L222.5,49.2 L223.7,49.6 L224.9,50.1 L226.2,50.5 L227.4,51.0 L228.7,51.4 L229.9,51.9 L231.1,52.3 L232.4,52.8 L233.6,53.2 L234.9,53.7 L236.1,54.2 L237.3,54.6 L238.6,55.1 L239.8,55.6 L241.1,56.1 L242.3,56.6 L243.5,57.1 L244.8,57.6 L246.0,58.1 L247.3,58.6 L248.5,59.1 L249.7,59.6 L251.0,60.1 L252.2,60.6 L253.5,61.1 L254.7,61.6 L255.9,62.2 L257.2,62.7 L258.4,63.2 L259.7,63.8 L260.9,64.3 L262.1,64.9 L263.4,65.4 L264.6,66.0 L265.9,66.5 L267.1,67.1 L268.3,67.6 L269.6,68.2 L270.8,68.8 L272.1,69.4 L273.3,69.9 L274.5,70.5 L275.8,71.1 L277.0,71.7 L278.3,72.3 L279.5,72.9 L280.7,73.5 L282.0,74.1 L283.2,74.8 L284.5,75.4 L285.7,76.0 L286.9,76.6 L288.2,77.3 L289.4,77.9 L290.7,78.6 L291.9,79.2 L293.1,79.9 L294.4,80.5 L295.6,81.2 L296.9,81.9 L298.1,82.5 L299.3,83.2 L300.6,83.9 L301.8,84.6 L303.1,85.3 L304.3,86.0 L305.5,86.7 L306.8,87.4 L308.0,88.1 L309.3,88.8 L310.5,89.6 L311.8,90.3 L313.0,91.0 L314.2,91.8 L315.5,92.5 L316.7,93.3 L318.0,94.0 L319.2,94.8 L320.4,95.5 L321.7,96.3 L322.9,97.1 L324.2,97.9 L325.4,98.7 L326.6,99.5 L327.9,100.3 L329.1,101.1 L330.4,101.9 L331.6,102.7 L332.8,103.5 L334.1,104.4 L335.3,105.2 L336.6,106.1 L337.8,106.9 L339.0,107.8 L340.3,108.6 L341.5,109.5 L342.8,110.4 L344.0,111.3 L345.2,112.1 L346.5,113.0 L347.7,113.9 L349.0,114.9 L350.2,115.8 L351.4,116.7 L352.7,117.6 L353.9,118.5 L355.2,119.5 L356.4,120.4 L357.6,121.4 L358.9,122.4 L360.1,123.3 L361.4,124.3 L362.6,125.3 L363.8,126.3 L365.1,127.3 L366.3,128.3 L367.6,129.3 L368.8,130.3 L370.0,131.3 L371.3,132.4 L372.5,133.4 L373.8,134.5 L375.0,135.5 L376.2,136.6 L377.5,137.7 L378.7,138.7 L380.0,139.8 L381.2,140.9 L382.4,142.0 L383.7,143.1 L384.9,144.3 L386.2,145.4 L387.4,146.5 L388.6,147.7 L389.9,148.8 L391.1,150.0 L392.4,151.2 L393.6,152.3 L394.8,153.5 L396.1,154.7 L397.3,155.9 L398.6,157.2 L399.8,158.4 L401.1,159.6 L402.3,160.8 L403.5,162.1 L404.8,163.4 L406.0,164.6 L407.3,165.9 L408.5,167.2 L409.7,168.5 L411.0,169.8 L412.2,171.1 L413.5,172.4 L414.7,173.8 L415.9,175.1 L417.2,176.5 L418.4,177.8 L419.7,179.2 L420.9,180.6 L422.1,182.0 L423.4,183.4 L424.6,184.8 L425.9,186.2 L427.1,187.7 L428.3,189.1 L429.6,190.6 L430.8,192.0 L432.1,193.5 L433.3,195.0 L434.5,196.5 L435.8,198.0 L437.0,199.5 L438.3,201.1 L439.5,202.6 L440.7,204.1 L442.0,205.7 L443.2,207.3 L444.5,208.9 L445.7,210.5 L446.9,212.1 L448.2,213.7 L449.4,215.4 L450.7,217.0 L451.9,218.7 L453.1,220.3 L454.4,222.0 L455.6,223.7 L456.9,225.4 L458.1,227.1 L459.3,228.9 L460.6,230.6 L461.8,232.4 L463.1,234.1 L464.3,235.9 L465.5,237.7 L466.8,239.5 L468.0,241.4 L469.3,243.2 L470.5,245.1 L471.7,246.9 L473.0,248.8 L474.2,250.7 L475.5,252.6 L476.7,254.5 L477.9,256.4 L479.2,258.4 L480.4,260.3 L481.7,262.3 L482.9,264.3 L484.1,266.3 L485.4,268.3 L486.6,270.4 L487.9,272.4 L489.1,274.5 L490.4,276.6 L491.6,278.7 L492.8,280.8 L494.1,282.9 L495.3,285.0 L496.6,287.2 L497.8,289.4 L499.0,291.5 L500.3,293.7 L501.5,296.0 L502.8,298.2 L504.0,300.5 L505.2,302.7 L506.5,305.0 L507.7,307.3 L509.0,309.6 L510.2,312.0 L511.4,314.3 L512.7,316.7 L513.9,319.1 L515.2,321.5 L516.4,323.9 L517.6,326.3 L518.9,328.8 L520.1,331.3 L521.4,333.8 L522.6,336.3 L523.8,338.8 L525.1,341.3 L526.3,343.9 L527.6,346.5 L528.8,349.1 L530.0,351.7 L531.3,354.4 L532.5,357.0 L533.8,359.7 L535.0,362.4 \" stroke=\"rgb( 0, 0, 255)\"/></g>\n",
"\t</g>\n",
"<g color=\"white\" fill=\"none\" stroke=\"rgb( 0, 0, 255)\" 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": [
"Amt_numerical=mod_secant(@(A) car_payments(A,700000,0.0875,30,0),1e-6,50,0.001)\n",
"car_payments(Amt_numerical,700000,0.0875,30,1)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ans = 1.9681e+06\r\n"
]
}
],
"source": [
"Amt_numerical*12*30"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Amortization calculation makes the same calculation for the monthly payment amount, A, paying off the principle amount, P, over n pay periods with monthly interest rate, r. "
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Amt = 566.14\r\n"
]
}
],
"source": [
"% Amortization calculation\n",
"A = @(P,r,n) P*(r*(1+r)^n)./((1+r)^n-1);\n",
"Amt=A(30000,0.05/12,5*12)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Matlab's function\n",
"\n",
"Matlab and Octave combine bracketing and open methods in the `fzero` function. "
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"'fzero' is a function from the file /usr/share/octave/4.0.0/m/optimization/fzero.m\n",
"\n",
" -- Function File: fzero (FUN, X0)\n",
" -- Function File: fzero (FUN, X0, OPTIONS)\n",
" -- Function File: [X, FVAL, INFO, OUTPUT] = fzero (...)\n",
" Find a zero of a univariate function.\n",
"\n",
" FUN is a function handle, inline function, or string containing the\n",
" name of the function to evaluate.\n",
"\n",
" X0 should be a two-element vector specifying two points which\n",
" bracket a zero. In other words, there must be a change in sign of\n",
" the function between X0(1) and X0(2). More mathematically, the\n",
" following must hold\n",
"\n",
" sign (FUN(X0(1))) * sign (FUN(X0(2))) <= 0\n",
"\n",
" If X0 is a single scalar then several nearby and distant values are\n",
" probed in an attempt to obtain a valid bracketing. If this is not\n",
" successful, the function fails.\n",
"\n",
" OPTIONS is a structure specifying additional options. Currently,\n",
" 'fzero' recognizes these options: \"FunValCheck\", \"OutputFcn\",\n",
" \"TolX\", \"MaxIter\", \"MaxFunEvals\". For a description of these\n",
" options, see *note optimset: XREFoptimset.\n",
"\n",
" On exit, the function returns X, the approximate zero point and\n",
" FVAL, the function value thereof.\n",
"\n",
" INFO is an exit flag that can have these values:\n",
"\n",
" * 1 The algorithm converged to a solution.\n",
"\n",
" * 0 Maximum number of iterations or function evaluations has\n",
" been reached.\n",
"\n",
" * -1 The algorithm has been terminated from user output\n",
" function.\n",
"\n",
" * -5 The algorithm may have converged to a singular point.\n",
"\n",
" OUTPUT is a structure containing runtime information about the\n",
" 'fzero' algorithm. Fields in the structure are:\n",
"\n",
" * iterations Number of iterations through loop.\n",
"\n",
" * nfev Number of function evaluations.\n",
"\n",
" * bracketx A two-element vector with the final bracketing of the\n",
" zero along the x-axis.\n",
"\n",
" * brackety A two-element vector with the final bracketing of the\n",
" zero along the y-axis.\n",
"\n",
" See also: optimset, fsolve.\n",
"\n",
"Additional help for built-in functions and operators is\n",
"available in the online version of the manual. Use the command\n",
"'doc <topic>' to search the manual index.\n",
"\n",
"Help and information about Octave is also available on the WWW\n",
"at http://www.octave.org and via the help@octave.org\n",
"mailing list.\n"
]
}
],
"source": [
"help fzero"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ans = 563.79\r\n"
]
}
],
"source": [
"fzero(@(A) car_payments(A,30000,0.05,5,0),500)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Comparison of Solvers\n",
"\n",
"It's helpful to compare to the convergence of different routines to see how quickly you find a solution. \n",
"\n",
"Comparing the freefall example\n"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"warning: axis: omitting non-positive data in log plot\n",
"warning: called from\n",
" __line__ at line 120 column 16\n",
" line at line 56 column 8\n",
" __plt__>__plt2vv__ at line 500 column 10\n",
" __plt__>__plt2__ at line 246 column 14\n",
" __plt__ at line 133 column 15\n",
" semilogy at line 60 column 10\n",
"warning: axis: omitting non-positive data in log plot\n",
"warning: axis: omitting non-positive data in log plot\n",
"warning: axis: omitting non-positive data in log plot\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=\"53.9,384.0 534.9,384.0 534.9,16.8 53.9,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=\"M53.9,384.0 L66.4,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(45.6,390.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">-14</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,343.2 L60.1,343.2 M535.0,343.2 L528.8,343.2 M53.9,302.4 L60.1,302.4 M535.0,302.4 L528.8,302.4 M53.9,261.6 L60.1,261.6 M535.0,261.6 L528.8,261.6 M53.9,220.8 L60.1,220.8 M535.0,220.8 L528.8,220.8 M53.9,179.9 L60.1,179.9 M535.0,179.9 L528.8,179.9 M53.9,139.1 L60.1,139.1 M535.0,139.1 L528.8,139.1 M53.9,98.3 L60.1,98.3 M535.0,98.3 L528.8,98.3 M53.9,57.5 L60.1,57.5 M535.0,57.5 L528.8,57.5 M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,343.2 L66.4,343.2 M535.0,343.2 L522.5,343.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(45.6,349.2)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">-12</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,302.4 L60.1,302.4 M535.0,302.4 L528.8,302.4 M53.9,261.6 L60.1,261.6 M535.0,261.6 L528.8,261.6 M53.9,220.8 L60.1,220.8 M535.0,220.8 L528.8,220.8 M53.9,179.9 L60.1,179.9 M535.0,179.9 L528.8,179.9 M53.9,139.1 L60.1,139.1 M535.0,139.1 L528.8,139.1 M53.9,98.3 L60.1,98.3 M535.0,98.3 L528.8,98.3 M53.9,57.5 L60.1,57.5 M535.0,57.5 L528.8,57.5 M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,302.4 L66.4,302.4 M535.0,302.4 L522.5,302.4 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(45.6,308.4)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">-10</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,261.6 L60.1,261.6 M535.0,261.6 L528.8,261.6 M53.9,220.8 L60.1,220.8 M535.0,220.8 L528.8,220.8 M53.9,179.9 L60.1,179.9 M535.0,179.9 L528.8,179.9 M53.9,139.1 L60.1,139.1 M535.0,139.1 L528.8,139.1 M53.9,98.3 L60.1,98.3 M535.0,98.3 L528.8,98.3 M53.9,57.5 L60.1,57.5 M535.0,57.5 L528.8,57.5 M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,261.6 L66.4,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(45.6,267.6)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">-8</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,220.8 L60.1,220.8 M535.0,220.8 L528.8,220.8 M53.9,179.9 L60.1,179.9 M535.0,179.9 L528.8,179.9 M53.9,139.1 L60.1,139.1 M535.0,139.1 L528.8,139.1 M53.9,98.3 L60.1,98.3 M535.0,98.3 L528.8,98.3 M53.9,57.5 L60.1,57.5 M535.0,57.5 L528.8,57.5 M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,220.8 L66.4,220.8 M535.0,220.8 L522.5,220.8 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(45.6,226.8)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">-6</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,179.9 L60.1,179.9 M535.0,179.9 L528.8,179.9 M53.9,139.1 L60.1,139.1 M535.0,139.1 L528.8,139.1 M53.9,98.3 L60.1,98.3 M535.0,98.3 L528.8,98.3 M53.9,57.5 L60.1,57.5 M535.0,57.5 L528.8,57.5 M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,179.9 L66.4,179.9 M535.0,179.9 L522.5,179.9 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(45.6,185.9)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">-4</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,139.1 L60.1,139.1 M535.0,139.1 L528.8,139.1 M53.9,98.3 L60.1,98.3 M535.0,98.3 L528.8,98.3 M53.9,57.5 L60.1,57.5 M535.0,57.5 L528.8,57.5 M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,139.1 L66.4,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(45.6,145.1)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">-2</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,98.3 L60.1,98.3 M535.0,98.3 L528.8,98.3 M53.9,57.5 L60.1,57.5 M535.0,57.5 L528.8,57.5 M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,98.3 L66.4,98.3 M535.0,98.3 L522.5,98.3 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(45.6,104.3)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">0</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,57.5 L60.1,57.5 M535.0,57.5 L528.8,57.5 M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,57.5 L66.4,57.5 M535.0,57.5 L522.5,57.5 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(45.6,63.5)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">2</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,16.7 L66.4,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(45.6,22.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">4</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,384.0 L53.9,371.5 M53.9,16.7 L53.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(53.9,408.0)\">\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=\"M114.0,384.0 L114.0,371.5 M114.0,16.7 L114.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(114.0,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">50</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=\"M174.2,384.0 L174.2,371.5 M174.2,16.7 L174.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(174.2,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">100</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=\"M234.3,384.0 L234.3,371.5 M234.3,16.7 L234.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(234.3,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">150</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=\"M294.5,384.0 L294.5,371.5 M294.5,16.7 L294.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(294.5,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">200</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=\"M354.6,384.0 L354.6,371.5 M354.6,16.7 L354.6,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(354.6,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">250</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=\"M414.7,384.0 L414.7,371.5 M414.7,16.7 L414.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(414.7,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">300</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=\"M474.9,384.0 L474.9,371.5 M474.9,16.7 L474.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(474.9,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">350</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=\"{}\">400</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=\"M53.9,16.7 L53.9,384.0 L535.0,384.0 L535.0,16.7 L53.9,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",
"<g color=\"black\" fill=\"none\" stroke=\"black\" 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<path d=\"M293.7,217.7 L293.7,25.7 L526.7,25.7 L526.7,217.7 L293.7,217.7 Z \" stroke=\"black\"/></g>\n",
"\t<g id=\"gnuplot_plot_1a\"><title>newton-raphson</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<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(526.7,55.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">newton-raphson</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M304.9,49.7 L358.7,49.7 M55.1,75.9 L80.4,114.0 L105.6,156.7 L130.9,199.4 L156.1,242.2 L181.4,284.9 L206.6,327.6 \" stroke=\"rgb( 0, 0, 255)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_2a\"><title>mod-secant</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(526.7,103.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">mod-secant</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M304.9,97.7 L358.7,97.7 M55.1,29.6 L80.4,378.2 L105.6,378.2 L130.9,378.2 L156.1,378.2 L181.4,378.2 L206.6,378.2 L231.9,378.2 L257.2,378.2 L282.4,378.2 L307.7,378.2 L332.9,378.2 L358.2,378.2 L383.5,378.2 L408.7,378.2 L434.0,378.2 L459.2,378.2 L484.5,378.2 L509.7,378.2 L535.0,378.2 \" stroke=\"rgb( 0, 128, 0)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_3a\"><title>false point</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(526.7,151.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">false point</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M304.9,145.7 L358.7,145.7 M55.1,94.5 L80.4,108.9 L105.6,127.2 L130.9,146.2 L156.1,165.3 L181.4,184.4 L206.6,203.5 L231.9,222.6 L257.2,241.7 L282.4,260.8 L307.7,279.9 L332.9,298.9 L358.2,318.0 L383.5,337.2 L408.7,356.6 L434.0,372.8 \" stroke=\"rgb(255, 0, 0)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_4a\"><title>bisection</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(526.7,199.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">bisection</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M304.9,193.7 L358.7,193.7 M55.1,115.1 L80.4,228.6 L105.6,352.0 \" stroke=\"rgb( 0, 191, 191)\"/></g>\n",
"\t</g>\n",
"<g color=\"white\" fill=\"none\" stroke=\"rgb( 0, 191, 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": [
"N=20;\n",
"iterations = linspace(1,400,N);\n",
"ea_nr=zeros(1,N); % appr error Newton-Raphson\n",
"ea_ms=zeros(1,N); % appr error Modified Secant\n",
"ea_fp=zeros(1,N); % appr error false point method\n",
"ea_bs=zeros(1,N); % appr error bisect method\n",
"for i=1:length(iterations)\n",
" [root_nr,ea_nr(i),iter_nr]=newtraph(f_m,df_m,300,0,iterations(i));\n",
" [root_ms,ea_ms(i),iter_ms]=mod_secant(f_m,1e-6,300,0,iterations(i));\n",
" [root_fp,ea_fp(i),iter_fp]=falsepos(f_m,1,300,0,iterations(i));\n",
" [root_bs,ea_bs(i),iter_bs]=bisect(f_m,1,300,0,iterations(i));\n",
"end\n",
"\n",
"setdefaults\n",
"semilogy(iterations,abs(ea_nr),iterations,abs(ea_ms),iterations,abs(ea_fp),iterations,abs(ea_bs))\n",
"legend('newton-raphson','mod-secant','false point','bisection')"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ea_nr =\n",
"\n",
" Columns 1 through 8:\n",
"\n",
" 6.36591 0.06436 0.00052 0.00000 0.00000 0.00000 0.00000 0.00000\n",
"\n",
" Columns 9 through 16:\n",
"\n",
" 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000\n",
"\n",
" Columns 17 through 20:\n",
"\n",
" 0.00000 0.00000 0.00000 0.00000\n",
"\n"
]
}
],
"source": [
"ea_nr"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"warning: axis: omitting non-positive data in log plot\n",
"warning: called from\n",
" __line__ at line 120 column 16\n",
" line at line 56 column 8\n",
" __plt__>__plt2vv__ at line 500 column 10\n",
" __plt__>__plt2__ at line 246 column 14\n",
" __plt__ at line 133 column 15\n",
" semilogy at line 60 column 10\n",
"warning: axis: omitting non-positive data in log plot\n",
"warning: axis: omitting non-positive data in log plot\n",
"warning: axis: omitting non-positive data in log plot\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=\"53.9,384.0 534.9,384.0 534.9,16.8 53.9,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=\"M53.9,364.7 L60.1,364.7 M535.0,364.7 L528.8,364.7 M53.9,326.0 L60.1,326.0 M535.0,326.0 L528.8,326.0 M53.9,287.3 L60.1,287.3 M535.0,287.3 L528.8,287.3 M53.9,248.7 L60.1,248.7 M535.0,248.7 L528.8,248.7 M53.9,210.0 L60.1,210.0 M535.0,210.0 L528.8,210.0 M53.9,171.4 L60.1,171.4 M535.0,171.4 L528.8,171.4 M53.9,132.7 L60.1,132.7 M535.0,132.7 L528.8,132.7 M53.9,94.0 L60.1,94.0 M535.0,94.0 L528.8,94.0 M53.9,55.4 L60.1,55.4 M535.0,55.4 L528.8,55.4 M53.9,364.7 L66.4,364.7 M535.0,364.7 L522.5,364.7 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(45.6,370.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">-14</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,326.0 L60.1,326.0 M535.0,326.0 L528.8,326.0 M53.9,287.3 L60.1,287.3 M535.0,287.3 L528.8,287.3 M53.9,248.7 L60.1,248.7 M535.0,248.7 L528.8,248.7 M53.9,210.0 L60.1,210.0 M535.0,210.0 L528.8,210.0 M53.9,171.4 L60.1,171.4 M535.0,171.4 L528.8,171.4 M53.9,132.7 L60.1,132.7 M535.0,132.7 L528.8,132.7 M53.9,94.0 L60.1,94.0 M535.0,94.0 L528.8,94.0 M53.9,55.4 L60.1,55.4 M535.0,55.4 L528.8,55.4 M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,326.0 L66.4,326.0 M535.0,326.0 L522.5,326.0 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(45.6,332.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">-12</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,287.3 L60.1,287.3 M535.0,287.3 L528.8,287.3 M53.9,248.7 L60.1,248.7 M535.0,248.7 L528.8,248.7 M53.9,210.0 L60.1,210.0 M535.0,210.0 L528.8,210.0 M53.9,171.4 L60.1,171.4 M535.0,171.4 L528.8,171.4 M53.9,132.7 L60.1,132.7 M535.0,132.7 L528.8,132.7 M53.9,94.0 L60.1,94.0 M535.0,94.0 L528.8,94.0 M53.9,55.4 L60.1,55.4 M535.0,55.4 L528.8,55.4 M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,287.3 L66.4,287.3 M535.0,287.3 L522.5,287.3 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(45.6,293.3)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">-10</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,248.7 L60.1,248.7 M535.0,248.7 L528.8,248.7 M53.9,210.0 L60.1,210.0 M535.0,210.0 L528.8,210.0 M53.9,171.4 L60.1,171.4 M535.0,171.4 L528.8,171.4 M53.9,132.7 L60.1,132.7 M535.0,132.7 L528.8,132.7 M53.9,94.0 L60.1,94.0 M535.0,94.0 L528.8,94.0 M53.9,55.4 L60.1,55.4 M535.0,55.4 L528.8,55.4 M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,248.7 L66.4,248.7 M535.0,248.7 L522.5,248.7 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(45.6,254.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">-8</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,210.0 L60.1,210.0 M535.0,210.0 L528.8,210.0 M53.9,171.4 L60.1,171.4 M535.0,171.4 L528.8,171.4 M53.9,132.7 L60.1,132.7 M535.0,132.7 L528.8,132.7 M53.9,94.0 L60.1,94.0 M535.0,94.0 L528.8,94.0 M53.9,55.4 L60.1,55.4 M535.0,55.4 L528.8,55.4 M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,210.0 L66.4,210.0 M535.0,210.0 L522.5,210.0 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(45.6,216.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">-6</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,171.4 L60.1,171.4 M535.0,171.4 L528.8,171.4 M53.9,132.7 L60.1,132.7 M535.0,132.7 L528.8,132.7 M53.9,94.0 L60.1,94.0 M535.0,94.0 L528.8,94.0 M53.9,55.4 L60.1,55.4 M535.0,55.4 L528.8,55.4 M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,171.4 L66.4,171.4 M535.0,171.4 L522.5,171.4 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(45.6,177.4)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">-4</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,132.7 L60.1,132.7 M535.0,132.7 L528.8,132.7 M53.9,94.0 L60.1,94.0 M535.0,94.0 L528.8,94.0 M53.9,55.4 L60.1,55.4 M535.0,55.4 L528.8,55.4 M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,132.7 L66.4,132.7 M535.0,132.7 L522.5,132.7 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(45.6,138.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">-2</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,94.0 L60.1,94.0 M535.0,94.0 L528.8,94.0 M53.9,55.4 L60.1,55.4 M535.0,55.4 L528.8,55.4 M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,94.0 L66.4,94.0 M535.0,94.0 L522.5,94.0 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(45.6,100.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">0</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,55.4 L60.1,55.4 M535.0,55.4 L528.8,55.4 M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,55.4 L66.4,55.4 M535.0,55.4 L522.5,55.4 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(45.6,61.4)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">2</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,16.7 L60.1,16.7 M535.0,16.7 L528.8,16.7 M53.9,16.7 L66.4,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(45.6,22.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</tspan><tspan dy=\"-8.00px\" font-family=\"{}\" font-size=\"12.8\">4</tspan><tspan dy=\"8.00\" font-size=\"16.0\"/></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=\"M53.9,384.0 L53.9,371.5 M53.9,16.7 L53.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(53.9,408.0)\">\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=\"M150.1,384.0 L150.1,371.5 M150.1,16.7 L150.1,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(150.1,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">10</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=\"M246.3,384.0 L246.3,371.5 M246.3,16.7 L246.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(246.3,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">20</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=\"M342.6,384.0 L342.6,371.5 M342.6,16.7 L342.6,29.2 \" stroke=\"black\"/>\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"middle\" transform=\"translate(342.6,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">30</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=\"M438.8,384.0 L438.8,371.5 M438.8,16.7 L438.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(438.8,408.0)\">\n",
"\t\t<text><tspan font-family=\"{}\">40</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=\"{}\">50</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=\"M53.9,16.7 L53.9,384.0 L535.0,384.0 L535.0,16.7 L53.9,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",
"<g color=\"black\" fill=\"none\" stroke=\"black\" 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<path d=\"M293.7,217.7 L293.7,25.7 L526.7,25.7 L526.7,217.7 L293.7,217.7 Z \" stroke=\"black\"/></g>\n",
"\t<g id=\"gnuplot_plot_1a\"><title>newton-raphson</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<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(526.7,55.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">newton-raphson</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M304.9,49.7 L358.7,49.7 M63.5,55.4 L88.3,73.8 L113.2,73.8 L138.0,73.8 L162.8,73.8 L187.6,73.8 L212.4,73.8 L237.2,73.8 L262.0,73.8 L286.9,73.8 L311.7,73.8 L336.5,73.8 L361.3,73.8 L386.1,73.9 L410.9,75.8 L435.7,87.7 L460.6,221.4 \" stroke=\"rgb( 0, 0, 255)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_2a\"><title>mod-secant</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(526.7,103.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">mod-secant</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M304.9,97.7 L358.7,97.7 M63.5,55.4 L88.3,73.8 L113.2,73.8 L138.0,73.8 L162.8,73.8 L187.6,73.8 L212.4,73.8 L237.2,73.8 L262.0,73.8 L286.9,73.8 L311.7,73.8 L336.5,73.8 L361.3,73.8 L386.1,73.9 L410.9,75.8 L435.7,87.7 L460.6,221.0 \" stroke=\"rgb( 0, 128, 0)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_3a\"><title>false point</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(526.7,151.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">false point</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M304.9,145.7 L358.7,145.7 M63.5,94.0 L88.3,94.0 L113.2,94.0 L138.0,94.0 L162.8,94.0 L187.6,94.0 L212.4,94.0 L237.2,94.0 L262.0,94.0 L286.9,94.0 L311.7,94.0 L336.5,94.0 L361.3,94.0 L386.1,94.0 L410.9,94.0 L435.7,94.0 L460.6,94.0 L485.4,94.0 L510.2,94.0 L535.0,94.0 \" stroke=\"rgb(255, 0, 0)\"/></g>\n",
"\t</g>\n",
"\t<g id=\"gnuplot_plot_4a\"><title>bisection</title>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<g fill=\"rgb(0,0,0)\" font-family=\"{}\" font-size=\"16.00\" stroke=\"none\" text-anchor=\"end\" transform=\"translate(526.7,199.7)\">\n",
"\t\t<text><tspan font-family=\"{}\">bisection</tspan></text>\n",
"\t</g>\n",
"</g>\n",
"<g color=\"black\" fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-width=\"3.00\">\n",
"\t<path d=\"M304.9,193.7 L358.7,193.7 M63.5,17.1 L88.3,100.3 L113.2,107.1 L138.0,117.6 L162.8,144.5 L187.6,156.2 L212.4,164.4 L237.2,191.1 L262.0,202.7 L286.9,211.0 L311.7,222.6 L336.5,249.3 L361.3,260.9 L386.1,269.1 L410.9,295.8 L435.7,307.5 L460.6,315.7 L485.4,327.3 L510.2,354.0 L535.0,365.7 \" stroke=\"rgb( 0, 191, 191)\"/></g>\n",
"\t</g>\n",
"<g color=\"white\" fill=\"none\" stroke=\"rgb( 0, 191, 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": [
"N=20;\n",
"f= @(x) x^10-1;\n",
"df=@(x) 10*x^9;\n",
"iterations = linspace(1,50,N);\n",
"ea_nr=zeros(1,N); % appr error Newton-Raphson\n",
"ea_ms=zeros(1,N); % appr error Modified Secant\n",
"ea_fp=zeros(1,N); % appr error false point method\n",
"ea_bs=zeros(1,N); % appr error bisect method\n",
"for i=1:length(iterations)\n",
" [root_nr,ea_nr(i),iter_nr]=newtraph(f,df,0.5,0,iterations(i));\n",
" [root_ms,ea_ms(i),iter_ms]=mod_secant(f,1e-6,0.5,0,iterations(i));\n",
" [root_fp,ea_fp(i),iter_fp]=falsepos(f,0,5,0,iterations(i));\n",
" [root_bs,ea_bs(i),iter_bs]=bisect(f,0,5,0,iterations(i));\n",
"end\n",
" \n",
"semilogy(iterations,abs(ea_nr),iterations,abs(ea_ms),iterations,abs(ea_fp),iterations,abs(ea_bs))\n",
"legend('newton-raphson','mod-secant','false point','bisection')"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ea_nr =\n",
"\n",
" Columns 1 through 7:\n",
"\n",
" 99.03195 11.11111 11.11111 11.11111 11.11111 11.11111 11.11111\n",
"\n",
" Columns 8 through 14:\n",
"\n",
" 11.11111 11.11111 11.11111 11.11109 11.11052 11.10624 10.99684\n",
"\n",
" Columns 15 through 20:\n",
"\n",
" 8.76956 2.12993 0.00000 0.00000 0.00000 0.00000\n",
"\n",
"ans = 16.208\n"
]
}
],
"source": [
"ea_nr\n",
"newtraph(f,df,0.5,0,12)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ans = 1.9683e+23\r\n"
]
}
],
"source": [
"df(300)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"f =\n",
"\n",
"@(x) tan (x) - (x - 1) .^ 2\n",
"\n",
"ans = 0.37375\n"
]
}
],
"source": [
"% our class function\n",
"f= @(x) tan(x)-(x-1).^2\n",
"mod_secant(f,1e-3,1)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ans = -3.5577e-13\r\n"
]
}
],
"source": [
"f(ans)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ans = 0.39218\n",
"ans = 0.39219\n"
]
}
],
"source": [
"tan(0.37375)\n",
"(0.37375-1)^2"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ans =\n",
"\n",
" Columns 1 through 8:\n",
"\n",
" -1.0000 1.5574 -3.1850 -4.1425 -7.8422 -19.3805 -25.2910 -35.1286\n",
"\n",
" Columns 9 through 11:\n",
"\n",
" -55.7997 -64.4523 -80.3516\n",
"\n"
]
}
],
"source": [
"f([0:10])"
]
},
{
"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
}