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