| 1 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Gleichungen lösen</title><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"><link rel="home" href="index.html" title="Genius-Handbuch"><link rel="up" href="ch11.html" title="Chapter 11. Liste der GEL-Funktionen"><link rel="prev" href="ch11s12.html" title="Funktionen"><link rel="next" href="ch11s14.html" title="Statistik"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Gleichungen lösen</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch11s12.html">Prev</a> </td><th width="60%" align="center">Chapter 11. Liste der GEL-Funktionen</th><td width="20%" align="right"> <a accesskey="n" href="ch11s14.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="genius-gel-function-list-equation-solving"></a>Gleichungen lösen</h2></div></div></div><div class="variablelist"><dl class="variablelist"><dt><span lang="en" class="term"><a name="gel-function-CubicFormula"></a>CubicFormula</span></dt><dd><pre class="synopsis">CubicFormula (p)</pre><p lang="en"> |
| 2 | Compute roots of a cubic (degree 3) polynomial using the |
| 3 | cubic formula. The polynomial should be given as a |
| 4 | vector of coefficients. That is |
| 5 | <strong class="userinput"><code>4*x^3 + 2*x + 1</code></strong> corresponds to the vector |
| 6 | <strong class="userinput"><code>[1,2,0,4]</code></strong>. |
| 7 | Returns a column vector of the three solutions. The first solution is always |
| 8 | the real one as a cubic always has one real solution. |
| 9 | </p><p lang="en"> |
| 10 | See |
| 11 | <a class="ulink" href="http://planetmath.org/CubicFormula" target="_top">Planetmath</a>, |
| 12 | <a class="ulink" href="http://mathworld.wolfram.com/CubicFormula.html" target="_top">Mathworld</a>, or |
| 13 | <a class="ulink" href="https://en.wikipedia.org/wiki/Cubic_equation" target="_top">Wikipedia</a> for more information. |
| 14 | </p></dd><dt><span lang="en" class="term"><a name="gel-function-EulersMethod"></a>EulersMethod</span></dt><dd><pre class="synopsis">EulersMethod (f,x0,y0,x1,n)</pre><p lang="en"> |
| 15 | Use classical Euler's method to numerically solve y'=f(x,y) for |
| 16 | initial <code class="varname">x0</code>, <code class="varname">y0</code> going to |
| 17 | <code class="varname">x1</code> with <code class="varname">n</code> increments, |
| 18 | returns <code class="varname">y</code> at <code class="varname">x1</code>. |
| 19 | Unless you explicitly want to use Euler's method, you should really |
| 20 | think about using |
| 21 | <a class="link" href="ch11s13.html#gel-function-RungeKutta">RungeKutta</a> |
| 22 | for solving ODE. |
| 23 | </p><p lang="en"> |
| 24 | Systems can be solved by just having <code class="varname">y</code> be a |
| 25 | (column) vector everywhere. That is, <code class="varname">y0</code> can |
| 26 | be a vector in which case <code class="varname">f</code> should take a number |
| 27 | <code class="varname">x</code> and a vector of the same size for the second |
| 28 | argument and should return a vector of the same size. |
| 29 | </p><p lang="en"> |
| 30 | See |
| 31 | <a class="ulink" href="http://mathworld.wolfram.com/EulerForwardMethod.html" target="_top">Mathworld</a> or |
| 32 | <a class="ulink" href="https://en.wikipedia.org/wiki/Eulers_method" target="_top">Wikipedia</a> for more information. |
| 33 | </p></dd><dt><span lang="en" class="term"><a name="gel-function-EulersMethodFull"></a>EulersMethodFull</span></dt><dd><pre class="synopsis">EulersMethodFull (f,x0,y0,x1,n)</pre><p lang="en"> |
| 34 | Use classical Euler's method to numerically solve y'=f(x,y) for |
| 35 | initial <code class="varname">x0</code>, <code class="varname">y0</code> going to |
| 36 | <code class="varname">x1</code> with <code class="varname">n</code> increments, |
| 37 | returns an <strong class="userinput"><code>n+1</code></strong> by 2 matrix with the |
| 38 | <code class="varname">x</code> and <code class="varname">y</code> values. |
| 39 | Unless you explicitly want to use Euler's method, you should really |
| 40 | think about using |
| 41 | <a class="link" href="ch11s13.html#gel-function-RungeKuttaFull">RungeKuttaFull</a> |
| 42 | for solving ODE. |
| 43 | Suitable |
| 44 | for plugging into |
| 45 | <a class="link" href="ch11s20.html#gel-function-LinePlotDrawLine">LinePlotDrawLine</a> or |
| 46 | <a class="link" href="ch11s20.html#gel-function-LinePlotDrawPoints">LinePlotDrawPoints</a>. |
| 47 | </p><p lang="en"> |
| 48 | Example: |
| 49 | </p><pre lang="en" class="screen"><code class="prompt">genius></code> <strong class="userinput"><code>LinePlotClear();</code></strong> |
| 50 | <code class="prompt">genius></code> <strong class="userinput"><code>line = EulersMethodFull(`(x,y)=y,0,1.0,3.0,50);</code></strong> |
| 51 | <code class="prompt">genius></code> <strong class="userinput"><code>LinePlotDrawLine(line,"window","fit","color","blue","legend","Exponential growth");</code></strong> |
| 52 | </pre><p lang="en"> |
| 53 | </p><p lang="en"> |
| 54 | Systems can be solved by just having <code class="varname">y</code> be a |
| 55 | (column) vector everywhere. That is, <code class="varname">y0</code> can |
| 56 | be a vector in which case <code class="varname">f</code> should take a number |
| 57 | <code class="varname">x</code> and a vector of the same size for the second |
| 58 | argument and should return a vector of the same size. |
| 59 | </p><p lang="en"> |
| 60 | The output for a system is still a n by 2 matrix with the second |
| 61 | entry being a vector. If you wish to plot the line, make sure to use row vectors, and then flatten the matrix with |
| 62 | <a class="link" href="ch11s08.html#gel-function-ExpandMatrix">ExpandMatrix</a>, |
| 63 | and pick out the right columns. Example: |
| 64 | </p><pre lang="en" class="screen"><code class="prompt">genius></code> <strong class="userinput"><code>LinePlotClear();</code></strong> |
| 65 | <code class="prompt">genius></code> <strong class="userinput"><code>lines = EulersMethodFull(`(x,y)=[y@(2),-y@(1)],0,[1.0,1.0],10.0,500);</code></strong> |
| 66 | <code class="prompt">genius></code> <strong class="userinput"><code>lines = ExpandMatrix(lines);</code></strong> |
| 67 | <code class="prompt">genius></code> <strong class="userinput"><code>firstline = lines@(,[1,2]);</code></strong> |
| 68 | <code class="prompt">genius></code> <strong class="userinput"><code>secondline = lines@(,[1,3]);</code></strong> |
| 69 | <code class="prompt">genius></code> <strong class="userinput"><code>LinePlotWindow = [0,10,-2,2];</code></strong> |
| 70 | <code class="prompt">genius></code> <strong class="userinput"><code>LinePlotDrawLine(firstline,"color","blue","legend","First");</code></strong> |
| 71 | <code class="prompt">genius></code> <strong class="userinput"><code>LinePlotDrawPoints(secondline,"color","red","thickness",3,"legend","Second");</code></strong> |
| 72 | </pre><p lang="en"> |
| 73 | </p><p lang="en"> |
| 74 | See |
| 75 | <a class="ulink" href="http://mathworld.wolfram.com/EulerForwardMethod.html" target="_top">Mathworld</a> or |
| 76 | <a class="ulink" href="https://en.wikipedia.org/wiki/Eulers_method" target="_top">Wikipedia</a> for more information. |
| 77 | </p><p lang="en">Version 1.0.10 onwards.</p></dd><dt><span lang="en" class="term"><a name="gel-function-FindRootBisection"></a>FindRootBisection</span></dt><dd><pre class="synopsis">FindRootBisection (f,a,b,TOL,N)</pre><p lang="en">Find root of a function using the bisection method. |
| 78 | <code class="varname">a</code> and <code class="varname">b</code> are the initial guess interval, |
| 79 | <strong class="userinput"><code>f(a)</code></strong> and <strong class="userinput"><code>f(b)</code></strong> should have opposite signs. |
| 80 | <code class="varname">TOL</code> is the desired tolerance and |
| 81 | <code class="varname">N</code> is the limit on the number of iterations to run, 0 means no limit. The function returns a vector <strong class="userinput"><code>[success,value,iteration]</code></strong>, where <code class="varname">success</code> is a boolean indicating success, <code class="varname">value</code> is the last value computed, and <code class="varname">iteration</code> is the number of iterations done.</p></dd><dt><span lang="en" class="term"><a name="gel-function-FindRootFalsePosition"></a>FindRootFalsePosition</span></dt><dd><pre class="synopsis">FindRootFalsePosition (f,a,b,TOL,N)</pre><p lang="en">Find root of a function using the method of false position. |
| 82 | <code class="varname">a</code> and <code class="varname">b</code> are the initial guess interval, |
| 83 | <strong class="userinput"><code>f(a)</code></strong> and <strong class="userinput"><code>f(b)</code></strong> should have opposite signs. |
| 84 | <code class="varname">TOL</code> is the desired tolerance and |
| 85 | <code class="varname">N</code> is the limit on the number of iterations to run, 0 means no limit. The function returns a vector <strong class="userinput"><code>[success,value,iteration]</code></strong>, where <code class="varname">success</code> is a boolean indicating success, <code class="varname">value</code> is the last value computed, and <code class="varname">iteration</code> is the number of iterations done.</p></dd><dt><span lang="en" class="term"><a name="gel-function-FindRootMullersMethod"></a>FindRootMullersMethod</span></dt><dd><pre lang="en" class="synopsis">FindRootMullersMethod (f,x0,x1,x2,TOL,N)</pre><p lang="en">Find root of a function using the Muller's method. |
| 86 | <code class="varname">TOL</code> is the desired tolerance and |
| 87 | <code class="varname">N</code> is the limit on the number of iterations to run, 0 means no limit. The function returns a vector <strong class="userinput"><code>[success,value,iteration]</code></strong>, where <code class="varname">success</code> is a boolean indicating success, <code class="varname">value</code> is the last value computed, and <code class="varname">iteration</code> is the number of iterations done.</p></dd><dt><span lang="en" class="term"><a name="gel-function-FindRootSecant"></a>FindRootSecant</span></dt><dd><pre class="synopsis">FindRootSecant (f,a,b,TOL,N)</pre><p lang="en">Find root of a function using the secant method. |
| 88 | <code class="varname">a</code> and <code class="varname">b</code> are the initial guess interval, |
| 89 | <strong class="userinput"><code>f(a)</code></strong> and <strong class="userinput"><code>f(b)</code></strong> should have opposite signs. |
| 90 | <code class="varname">TOL</code> is the desired tolerance and |
| 91 | <code class="varname">N</code> is the limit on the number of iterations to run, 0 means no limit. The function returns a vector <strong class="userinput"><code>[success,value,iteration]</code></strong>, where <code class="varname">success</code> is a boolean indicating success, <code class="varname">value</code> is the last value computed, and <code class="varname">iteration</code> is the number of iterations done.</p></dd><dt><span lang="en" class="term"><a name="gel-function-HalleysMethod"></a>HalleysMethod</span></dt><dd><pre lang="en" class="synopsis">HalleysMethod (f,df,ddf,guess,epsilon,maxn)</pre><p lang="en">Find zeros using Halley's method. <code class="varname">f</code> is |
| 92 | the function, <code class="varname">df</code> is the derivative of |
| 93 | <code class="varname">f</code>, and <code class="varname">ddf</code> is the second derivative of |
| 94 | <code class="varname">f</code>. <code class="varname">guess</code> is the initial |
| 95 | guess. The function returns after two successive values are |
| 96 | within <code class="varname">epsilon</code> of each other, or after <code class="varname">maxn</code> tries, in which case the function returns <code class="constant">null</code> indicating failure. |
| 97 | </p><p lang="en"> |
| 98 | See also <a class="link" href="ch11s13.html#gel-function-NewtonsMethod"><code class="function">NewtonsMethod</code></a> and <a class="link" href="ch11s19.html#gel-function-SymbolicDerivative"><code class="function">SymbolicDerivative</code></a>. |
| 99 | </p><p lang="en"> |
| 100 | Example to find the square root of 10: |
| 101 | </p><pre lang="en" class="screen"><code class="prompt">genius></code> <strong class="userinput"><code>HalleysMethod(`(x)=x^2-10,`(x)=2*x,`(x)=2,3,10^-10,100)</code></strong> |
| 102 | </pre><p lang="en"> |
| 103 | </p><p lang="en"> |
| 104 | See |
| 105 | <a class="ulink" href="https://en.wikipedia.org/wiki/Halley%27s_method" target="_top">Wikipedia</a> for more information. |
| 106 | </p><p lang="en">Version 1.0.18 onwards.</p></dd><dt><span lang="en" class="term"><a name="gel-function-NewtonsMethod"></a>NewtonsMethod</span></dt><dd><pre lang="en" class="synopsis">NewtonsMethod (f,df,guess,epsilon,maxn)</pre><p lang="en">Find zeros using Newton's method. <code class="varname">f</code> is |
| 107 | the function and <code class="varname">df</code> is the derivative of |
| 108 | <code class="varname">f</code>. <code class="varname">guess</code> is the initial |
| 109 | guess. The function returns after two successive values are |
| 110 | within <code class="varname">epsilon</code> of each other, or after <code class="varname">maxn</code> tries, in which case the function returns <code class="constant">null</code> indicating failure. |
| 111 | </p><p lang="en"> |
| 112 | See also <a class="link" href="ch11s15.html#gel-function-NewtonsMethodPoly"><code class="function">NewtonsMethodPoly</code></a> and <a class="link" href="ch11s19.html#gel-function-SymbolicDerivative"><code class="function">SymbolicDerivative</code></a>. |
| 113 | </p><p lang="en"> |
| 114 | Example to find the square root of 10: |
| 115 | </p><pre lang="en" class="screen"><code class="prompt">genius></code> <strong class="userinput"><code>NewtonsMethod(`(x)=x^2-10,`(x)=2*x,3,10^-10,100)</code></strong> |
| 116 | </pre><p lang="en"> |
| 117 | </p><p lang="en"> |
| 118 | See |
| 119 | <a class="ulink" href="https://en.wikipedia.org/wiki/Newtons_method" target="_top">Wikipedia</a> for more information. |
| 120 | </p><p lang="en">Version 1.0.18 onwards.</p></dd><dt><span lang="en" class="term"><a name="gel-function-PolynomialRoots"></a>PolynomialRoots</span></dt><dd><pre class="synopsis">PolynomialRoots (p)</pre><p lang="en"> |
| 121 | Compute roots of a polynomial (degrees 1 through 4) |
| 122 | using one of the formulas for such polynomials. |
| 123 | The polynomial should be given as a |
| 124 | vector of coefficients. That is |
| 125 | <strong class="userinput"><code>4*x^3 + 2*x + 1</code></strong> corresponds to the vector |
| 126 | <strong class="userinput"><code>[1,2,0,4]</code></strong>. |
| 127 | Returns a column vector of the solutions. |
| 128 | </p><p lang="en"> |
| 129 | The function calls |
| 130 | <a class="link" href="ch11s13.html#gel-function-QuadraticFormula">QuadraticFormula</a>, |
| 131 | <a class="link" href="ch11s13.html#gel-function-CubicFormula">CubicFormula</a>, and |
| 132 | <a class="link" href="ch11s13.html#gel-function-QuarticFormula">QuarticFormula</a>. |
| 133 | </p></dd><dt><span lang="en" class="term"><a name="gel-function-QuadraticFormula"></a>QuadraticFormula</span></dt><dd><pre class="synopsis">QuadraticFormula (p)</pre><p lang="en"> |
| 134 | Compute roots of a quadratic (degree 2) polynomial using the |
| 135 | quadratic formula. The polynomial should be given as a |
| 136 | vector of coefficients. That is |
| 137 | <strong class="userinput"><code>3*x^2 + 2*x + 1</code></strong> corresponds to the vector |
| 138 | <strong class="userinput"><code>[1,2,3]</code></strong>. |
| 139 | Returns a column vector of the two solutions. |
| 140 | </p><p lang="en"> |
| 141 | See |
| 142 | <a class="ulink" href="http://planetmath.org/QuadraticFormula" target="_top">Planetmath</a>, or |
| 143 | <a class="ulink" href="http://mathworld.wolfram.com/QuadraticFormula.html" target="_top">Mathworld</a>, or |
| 144 | <a class="ulink" href="https://en.wikipedia.org/wiki/Quadratic_formula" target="_top">Wikipedia</a> for more information. |
| 145 | </p></dd><dt><span lang="en" class="term"><a name="gel-function-QuarticFormula"></a>QuarticFormula</span></dt><dd><pre class="synopsis">QuarticFormula (p)</pre><p lang="en"> |
| 146 | Compute roots of a quartic (degree 4) polynomial using the |
| 147 | quartic formula. The polynomial should be given as a |
| 148 | vector of coefficients. That is |
| 149 | <strong class="userinput"><code>5*x^4 + 2*x + 1</code></strong> corresponds to the vector |
| 150 | <strong class="userinput"><code>[1,2,0,0,5]</code></strong>. |
| 151 | Returns a column vector of the four solutions. |
| 152 | </p><p lang="en"> |
| 153 | See |
| 154 | <a class="ulink" href="http://planetmath.org/QuarticFormula" target="_top">Planetmath</a>, |
| 155 | <a class="ulink" href="http://mathworld.wolfram.com/QuarticEquation.html" target="_top">Mathworld</a>, or |
| 156 | <a class="ulink" href="https://en.wikipedia.org/wiki/Quartic_equation" target="_top">Wikipedia</a> for more information. |
| 157 | </p></dd><dt><span lang="en" class="term"><a name="gel-function-RungeKutta"></a>RungeKutta</span></dt><dd><pre class="synopsis">RungeKutta (f,x0,y0,x1,n)</pre><p lang="en"> |
| 158 | Use classical non-adaptive fourth order Runge-Kutta method to |
| 159 | numerically solve |
| 160 | y'=f(x,y) for initial <code class="varname">x0</code>, <code class="varname">y0</code> |
| 161 | going to <code class="varname">x1</code> with <code class="varname">n</code> |
| 162 | increments, returns <code class="varname">y</code> at <code class="varname">x1</code>. |
| 163 | </p><p lang="en"> |
| 164 | Systems can be solved by just having <code class="varname">y</code> be a |
| 165 | (column) vector everywhere. That is, <code class="varname">y0</code> can |
| 166 | be a vector in which case <code class="varname">f</code> should take a number |
| 167 | <code class="varname">x</code> and a vector of the same size for the second |
| 168 | argument and should return a vector of the same size. |
| 169 | </p><p lang="en"> |
| 170 | See |
| 171 | <a class="ulink" href="http://mathworld.wolfram.com/Runge-KuttaMethod.html" target="_top">Mathworld</a> or |
| 172 | <a class="ulink" href="https://en.wikipedia.org/wiki/Runge-Kutta_methods" target="_top">Wikipedia</a> for more information. |
| 173 | </p></dd><dt><span lang="en" class="term"><a name="gel-function-RungeKuttaFull"></a>RungeKuttaFull</span></dt><dd><pre class="synopsis">RungeKuttaFull (f,x0,y0,x1,n)</pre><p lang="en"> |
| 174 | Use classical non-adaptive fourth order Runge-Kutta method to |
| 175 | numerically solve |
| 176 | y'=f(x,y) for initial <code class="varname">x0</code>, <code class="varname">y0</code> |
| 177 | going to <code class="varname">x1</code> with <code class="varname">n</code> |
| 178 | increments, |
| 179 | returns an <strong class="userinput"><code>n+1</code></strong> by 2 matrix with the |
| 180 | <code class="varname">x</code> and <code class="varname">y</code> values. Suitable |
| 181 | for plugging into |
| 182 | <a class="link" href="ch11s20.html#gel-function-LinePlotDrawLine">LinePlotDrawLine</a> or |
| 183 | <a class="link" href="ch11s20.html#gel-function-LinePlotDrawPoints">LinePlotDrawPoints</a>. |
| 184 | </p><p lang="en"> |
| 185 | Example: |
| 186 | </p><pre lang="en" class="screen"><code class="prompt">genius></code> <strong class="userinput"><code>LinePlotClear();</code></strong> |
| 187 | <code class="prompt">genius></code> <strong class="userinput"><code>line = RungeKuttaFull(`(x,y)=y,0,1.0,3.0,50);</code></strong> |
| 188 | <code class="prompt">genius></code> <strong class="userinput"><code>LinePlotDrawLine(line,"window","fit","color","blue","legend","Exponential growth");</code></strong> |
| 189 | </pre><p lang="en"> |
| 190 | </p><p lang="en"> |
| 191 | Systems can be solved by just having <code class="varname">y</code> be a |
| 192 | (column) vector everywhere. That is, <code class="varname">y0</code> can |
| 193 | be a vector in which case <code class="varname">f</code> should take a number |
| 194 | <code class="varname">x</code> and a vector of the same size for the second |
| 195 | argument and should return a vector of the same size. |
| 196 | </p><p lang="en"> |
| 197 | The output for a system is still a n by 2 matrix with the second |
| 198 | entry being a vector. If you wish to plot the line, make sure to use row vectors, and then flatten the matrix with |
| 199 | <a class="link" href="ch11s08.html#gel-function-ExpandMatrix">ExpandMatrix</a>, |
| 200 | and pick out the right columns. Example: |
| 201 | </p><pre lang="en" class="screen"><code class="prompt">genius></code> <strong class="userinput"><code>LinePlotClear();</code></strong> |
| 202 | <code class="prompt">genius></code> <strong class="userinput"><code>lines = RungeKuttaFull(`(x,y)=[y@(2),-y@(1)],0,[1.0,1.0],10.0,100);</code></strong> |
| 203 | <code class="prompt">genius></code> <strong class="userinput"><code>lines = ExpandMatrix(lines);</code></strong> |
| 204 | <code class="prompt">genius></code> <strong class="userinput"><code>firstline = lines@(,[1,2]);</code></strong> |
| 205 | <code class="prompt">genius></code> <strong class="userinput"><code>secondline = lines@(,[1,3]);</code></strong> |
| 206 | <code class="prompt">genius></code> <strong class="userinput"><code>LinePlotWindow = [0,10,-2,2];</code></strong> |
| 207 | <code class="prompt">genius></code> <strong class="userinput"><code>LinePlotDrawLine(firstline,"color","blue","legend","First");</code></strong> |
| 208 | <code class="prompt">genius></code> <strong class="userinput"><code>LinePlotDrawPoints(secondline,"color","red","thickness",3,"legend","Second");</code></strong> |
| 209 | </pre><p lang="en"> |
| 210 | </p><p lang="en"> |
| 211 | See |
| 212 | <a class="ulink" href="http://mathworld.wolfram.com/Runge-KuttaMethod.html" target="_top">Mathworld</a> or |
| 213 | <a class="ulink" href="https://en.wikipedia.org/wiki/Runge-Kutta_methods" target="_top">Wikipedia</a> for more information. |
| 214 | </p><p lang="en">Version 1.0.10 onwards.</p></dd></dl></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch11s12.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch11.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch11s14.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Funktionen </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Statistik</td></tr></table></div></body></html> |