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": 1,
"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": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"error_approx = 1\r\n"
]
}
],
"source": [
"f= @(x) exp(-x)-x;\n",
"df= @(x) -exp(-x)-1;\n",
"\n",
"x_i= 0;\n",
"error_approx = abs((x_r-x_i)/x_r)\n",
"x_r=x_i;\n"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"x_r = 0.50000\n",
"error_approx = 1\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": 22,
"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": 23,
"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": "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": 7,
"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": [
"ans = 142.74\r\n"
]
}
],
"source": [
"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": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ans = 142.74\r\n"
]
}
],
"source": [
"mod_secant(f_m,1e-6,50,0.00001)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"error: 'plot_bool' undefined near line 12 column 6\n",
"error: called from\n",
" car_payments at line 12 column 3\n",
" mod_secant at line 22 column 8\n",
"error: 'Amt' undefined near line 1 column 14\n",
"error: evaluating argument list element number 1\n"
]
}
],
"source": [
"Amt_numerical=mod_secant(@(A) car_payments(A,30000,0.05,5),1e-6,50,0.001)\n",
"car_payments(Amt,30000,0.05,5)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"error: 'Amt' undefined near line 1 column 1\r\n"
]
}
],
"source": [
"Amt*12*5"
]
},
{
"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": 12,
"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": 14,
"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": 15,
"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,81.9 L80.4,122.6 L105.6,165.4 L130.9,208.1 L156.1,250.8 L181.4,293.6 L206.6,336.0 \" 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,200,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",
"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": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ea_ms =\n",
"\n",
" Columns 1 through 6:\n",
"\n",
" 2.3382e+03 1.9171e-14 1.9171e-14 1.9171e-14 1.9171e-14 1.9171e-14\n",
"\n",
" Columns 7 through 12:\n",
"\n",
" 1.9171e-14 1.9171e-14 1.9171e-14 1.9171e-14 1.9171e-14 1.9171e-14\n",
"\n",
" Columns 13 through 18:\n",
"\n",
" 1.9171e-14 1.9171e-14 1.9171e-14 1.9171e-14 1.9171e-14 1.9171e-14\n",
"\n",
" Columns 19 and 20:\n",
"\n",
" 1.9171e-14 1.9171e-14\n",
"\n"
]
}
],
"source": [
"ea_ms"
]
},
{
"cell_type": "code",
"execution_count": 17,
"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": 18,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"ea_bs =\n",
"\n",
" Columns 1 through 6:\n",
"\n",
" 9.5357e+03 -4.7554e-01 -2.1114e-01 6.0163e-02 -2.4387e-03 6.1052e-04\n",
"\n",
" Columns 7 through 12:\n",
"\n",
" 2.2891e-04 -9.5367e-06 2.3842e-06 8.9407e-07 -2.2352e-07 9.3132e-09\n",
"\n",
" Columns 13 through 18:\n",
"\n",
" -2.3283e-09 -8.7311e-10 3.6380e-11 -9.0949e-12 -3.4106e-12 8.5265e-13\n",
"\n",
" Columns 19 and 20:\n",
"\n",
" -3.5527e-14 8.8818e-15\n",
"\n",
"ans = 16.208\n"
]
}
],
"source": [
"ea_bs\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": 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
}