add ode solver, tests and update docs

This commit is contained in:
2019-05-26 21:54:58 +02:00
parent 184e80269b
commit d0873a36da
33 changed files with 1821 additions and 396 deletions

289
docs/build/html/solver.html vendored Normal file
View File

@@ -0,0 +1,289 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>solver module &#8212; pylib 2019.5.19 documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/language_data.js"></script>
<script async="async" type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head><body>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="module-solver">
<span id="solver-module"></span><h1>solver module<a class="headerlink" href="#module-solver" title="Permalink to this headline"></a></h1>
<p>Numerical solver of ordinary differential equations.</p>
<p>Solves the initial value problem for systems of first order ordinary differential
equations.</p>
<dl class="field-list simple">
<dt class="field-odd">Date</dt>
<dd class="field-odd"><p>2015-09-21</p>
</dd>
</dl>
<span class="target" id="module-solver"></span><dl class="function">
<dt id="solver.e1">
<code class="descname">e1</code><span class="sig-paren">(</span><em>f</em>, <em>x0</em>, <em>t</em>, <em>*p</em>, <em>verbose=False</em><span class="sig-paren">)</span><a class="headerlink" href="#solver.e1" title="Permalink to this definition"></a></dt>
<dd><p>Explicit first-order method /
(standard, or forward) Euler method /
Runge-Kutta 1st order method.</p>
<p>de:
Eulersche Polygonzugverfahren / explizite Euler-Verfahren /
Euler-Cauchy-Verfahren / Euler-vorwärts-Verfahren</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>f</strong> (<em>function</em>) the function to solve</p></li>
<li><p><strong>x0</strong> (<em>list</em>) initial condition</p></li>
<li><p><strong>t</strong> (<em>list</em>) time</p></li>
<li><p><strong>*p</strong> parameters of the function (thickness, diameter, …)</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) print information (default = False)</p></li>
</ul>
</dd>
</dl>
<p>Approximate the solution of the initial value problem</p>
<div class="math notranslate nohighlight">
\[\begin{split}\dot{x} &amp;= f(t,x) \\
x(t_0) &amp;= x_0\end{split}\]</div>
<p>Choose a value h for the size of every step and set</p>
<div class="math notranslate nohighlight">
\[t_i = t_0 + i h ~,\quad i=1,2,\ldots,n\]</div>
<p>One step <span class="math notranslate nohighlight">\(h\)</span> of the Euler method from <span class="math notranslate nohighlight">\(t_i\)</span> to <span class="math notranslate nohighlight">\(t_{i+1}\)</span> is</p>
<div class="math notranslate nohighlight">
\[\begin{split}x_{i+1} &amp;= x_i + (t_{i+1}-t_i) f(t_i, x_i) \\
x_{i+1} &amp;= x_i + h f(t_i, x_i) \\\end{split}\]</div>
<p>Example 1:</p>
<div class="math notranslate nohighlight">
\[\begin{split}m\ddot{u} + d\dot{u} + ku = f(t) \\
\ddot{u} = m^{-1}(f(t) - d\dot{u} - ku) \\\end{split}\]</div>
<p>with</p>
<div class="math notranslate nohighlight">
\[\begin{split}x_1 &amp;= u &amp;\quad \dot{x}_1 = \dot{u} = x_2 \\
x_2 &amp;= \dot{u} &amp;\quad \dot{x}_2 = \ddot{u} \\\end{split}\]</div>
<p>becomes</p>
<div class="math notranslate nohighlight">
\[\begin{split}\dot{x}_1 &amp;= x_2 \\
\dot{x}_2 &amp;= m^{-1}(f(t) - d x_2 - k x_1) \\\end{split}\]</div>
<p>or</p>
<div class="math notranslate nohighlight">
\[\begin{split}\dot{x} &amp;= f(t,x) \\
\begin{bmatrix} \dot{x}_1 \\ \dot{x}_1 \end{bmatrix} &amp;=
\begin{bmatrix} x_2 \\ m^{-1}(f(t) - d x_2 - k x_1) \end{bmatrix} \\
&amp;=
\begin{bmatrix} 0 \\ m^{-1} f(t) \end{bmatrix} +
\begin{bmatrix} 0 &amp; 1 \\ -m^{-1} k &amp; -m^{-1} d \end{bmatrix}
\begin{bmatrix} x_1 \\ x_2 \end{bmatrix}\end{split}\]</div>
<p>Example 2:</p>
<div class="math notranslate nohighlight">
\[\begin{split}m(u)\ddot{u} + d(u,\dot{u})\dot{u} + k(u)u = f(t) \\
\ddot{u} = m^{-1}(u)(f(t) - d(u,\dot{u})\dot{u} - k(u)u) \\\end{split}\]</div>
<p>with</p>
<div class="math notranslate nohighlight">
\[\begin{split}x_1 &amp;= u &amp;\quad \dot{x}_1 = \dot{u} = x_2 \\
x_2 &amp;= \dot{u} &amp;\quad \dot{x}_2 = \ddot{u} \\\end{split}\]</div>
<p>becomes</p>
<div class="math notranslate nohighlight">
\[\begin{split}\dot{x}_1 &amp;= x_2 \\
\dot{x}_2 &amp;= m^{-1}(x_1)(f(t) - d(x_1,x_2) x_2 - k(x_1) x_1) \\\end{split}\]</div>
<p>or</p>
<div class="math notranslate nohighlight">
\[\begin{split}\dot{x} &amp;= f(t,x) \\
\begin{bmatrix} \dot{x}_1 \\ \dot{x}_2 \end{bmatrix} &amp;=
\begin{bmatrix} x_2 \\ m^{-1}(x_1)(f(t) - d(x_1,x_2) x_2 - k(x_1) x_1) \end{bmatrix} \\
&amp;=
\begin{bmatrix} 0 \\ m^{-1}(x_1) f(t) \end{bmatrix} +
\begin{bmatrix} 0 &amp; 1 \\ -m^{-1}(x_1) k(x_1) &amp; -m^{-1} d(x_1,x_2) \end{bmatrix}
\begin{bmatrix} x_1 \\ x_2 \end{bmatrix}\end{split}\]</div>
<p>The Euler method is a first-order method,
which means that the local error (error per step) is proportional to the
square of the step size, and the global error (error at a given time) is
proportional to the step size.</p>
</dd></dl>
<dl class="function">
<dt id="solver.e2">
<code class="descname">e2</code><span class="sig-paren">(</span><em>f</em>, <em>x0</em>, <em>t</em>, <em>*p</em>, <em>verbose=False</em><span class="sig-paren">)</span><a class="headerlink" href="#solver.e2" title="Permalink to this definition"></a></dt>
<dd><p>Explicit second-order method / Runge-Kutta 2nd order method.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>f</strong> (<em>function</em>) the function to solve</p></li>
<li><p><strong>x0</strong> (<em>list</em>) initial condition</p></li>
<li><p><strong>t</strong> (<em>list</em>) time</p></li>
<li><p><strong>*p</strong> parameters of the function (thickness, diameter, …)</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) print information (default = False)</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="solver.e4">
<code class="descname">e4</code><span class="sig-paren">(</span><em>f</em>, <em>x0</em>, <em>t</em>, <em>*p</em>, <em>verbose=False</em><span class="sig-paren">)</span><a class="headerlink" href="#solver.e4" title="Permalink to this definition"></a></dt>
<dd><p>Explicit fourth-order method / Runge-Kutta 4th order method.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>f</strong> (<em>function</em>) the function to solve</p></li>
<li><p><strong>x0</strong> (<em>list</em>) initial condition</p></li>
<li><p><strong>t</strong> (<em>list</em>) time</p></li>
<li><p><strong>*p</strong> parameters of the function (thickness, diameter, …)</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) print information (default = False)</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="solver.i1">
<code class="descname">i1</code><span class="sig-paren">(</span><em>f</em>, <em>x0</em>, <em>t</em>, <em>*p</em>, <em>max_iterations=1000</em>, <em>tol=1e-09</em>, <em>verbose=False</em><span class="sig-paren">)</span><a class="headerlink" href="#solver.i1" title="Permalink to this definition"></a></dt>
<dd><p>Implicite first-order method / backward Euler method.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>f</strong> (<em>function</em>) the function to solve</p></li>
<li><p><strong>x0</strong> (<em>list</em>) initial condition</p></li>
<li><p><strong>t</strong> (<em>list</em>) time</p></li>
<li><p><strong>*p</strong> parameters of the function (thickness, diameter, …)</p></li>
<li><p><strong>max_iterations</strong> (<em>int</em>) maximum number of iterations</p></li>
<li><p><strong>tol</strong> (<em>float</em>) tolerance against residuum (default = 1e-9)</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) print information (default = False)</p></li>
</ul>
</dd>
</dl>
<p>The backward Euler method has order one and is A-stable.</p>
</dd></dl>
<dl class="function">
<dt id="solver.newmark_newtonraphson">
<code class="descname">newmark_newtonraphson</code><span class="sig-paren">(</span><em>f</em>, <em>x0</em>, <em>xp0</em>, <em>xpp0</em>, <em>t</em>, <em>*p</em>, <em>gamma=0.5</em>, <em>beta=0.25</em>, <em>max_iterations=1000</em>, <em>tol=1e-09</em>, <em>verbose=False</em><span class="sig-paren">)</span><a class="headerlink" href="#solver.newmark_newtonraphson" title="Permalink to this definition"></a></dt>
<dd><p>Newmark method.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>f</strong> (<em>function</em>) the function to solve</p></li>
<li><p><strong>x0</strong> (<em>list</em>) initial condition</p></li>
<li><p><strong>xp0</strong> (<em>list</em>) initial condition</p></li>
<li><p><strong>xpp0</strong> (<em>list</em>) initial condition</p></li>
<li><p><strong>t</strong> (<em>list</em>) time</p></li>
<li><p><strong>*p</strong> parameters of the function (thickness, diameter, …)</p></li>
<li><p><strong>gamma</strong> (<em>float</em>) newmark parameter for velocity (default = 0.5)</p></li>
<li><p><strong>beta</strong> (<em>float</em>) newmark parameter for displacement (default = 0.25)</p></li>
<li><p><strong>max_iterations</strong> (<em>int</em>) maximum number of iterations</p></li>
<li><p><strong>tol</strong> (<em>float</em>) tolerance against residuum (default = 1e-9)</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) print information (default = False)</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="solver.newmark_newtonraphson_rdk">
<code class="descname">newmark_newtonraphson_rdk</code><span class="sig-paren">(</span><em>fnm</em>, <em>x0</em>, <em>xp0</em>, <em>xpp0</em>, <em>t</em>, <em>*p</em>, <em>gamma=0.5</em>, <em>beta=0.25</em>, <em>maxIterations=1000</em>, <em>tol=1e-09</em>, <em>verbose=False</em><span class="sig-paren">)</span><a class="headerlink" href="#solver.newmark_newtonraphson_rdk" title="Permalink to this definition"></a></dt>
<dd><p>Newmark method.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>f</strong> (<em>function</em>) the function to solve</p></li>
<li><p><strong>x0</strong> (<em>list</em>) initial condition</p></li>
<li><p><strong>xp0</strong> (<em>list</em>) initial condition</p></li>
<li><p><strong>xpp0</strong> (<em>list</em>) initial condition</p></li>
<li><p><strong>t</strong> (<em>list</em>) time</p></li>
<li><p><strong>*p</strong> parameters of the function (thickness, diameter, …)</p></li>
<li><p><strong>gamma</strong> (<em>float</em>) newmark parameter for velocity (default = 0.5)</p></li>
<li><p><strong>beta</strong> (<em>float</em>) newmark parameter for displacement (default = 0.25)</p></li>
<li><p><strong>max_iterations</strong> (<em>int</em>) maximum number of iterations</p></li>
<li><p><strong>tol</strong> (<em>float</em>) tolerance against residuum (default = 1e-9)</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) print information (default = False)</p></li>
</ul>
</dd>
</dl>
</dd></dl>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="index.html">pylib</a></h1>
<h3>Navigation</h3>
<div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="index.html">Documentation overview</a><ul>
</ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
</form>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
&copy;2019, Daniel Weschke.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 2.0.1</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
|
<a href="_sources/solver.rst.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>