add time module and move fixed-point iteration to own function

This commit is contained in:
2019-06-01 15:51:35 +02:00
parent 0162ce2701
commit 4ec84c49ac
18 changed files with 1148 additions and 270 deletions

View File

@@ -197,30 +197,14 @@ b &amp;= 1\end{split}\]</div>
<div class="section" id="module-numerical.ode">
<span id="numerical-ode-module"></span><h2>numerical.ode module<a class="headerlink" href="#module-numerical.ode" title="Permalink to this headline"></a></h2>
<p>Numerical solver of ordinary differential equations.</p>
<p>Solves the initial value problem for systems of first order 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-ode"></span><dl class="function">
<dt id="numerical.ode.dxdt_Dt">
<code class="descname">dxdt_Dt</code><span class="sig-paren">(</span><em>f</em>, <em>x</em>, <em>t</em>, <em>Dt</em>, <em>*p</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/numerical/ode.html#dxdt_Dt"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#numerical.ode.dxdt_Dt" title="Permalink to this definition"></a></dt>
<dd><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>) <span class="math notranslate nohighlight">\(f = \dot{x}\)</span></p></li>
<li><p><strong>Dt</strong> <span class="math notranslate nohighlight">\(\Delta{t}\)</span></p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><span class="math notranslate nohighlight">\(\Delta x = \dot{x} \Delta t\)</span></p>
</dd>
</dl>
</dd></dl>
<dl class="function">
<dt id="numerical.ode.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="reference internal" href="_modules/numerical/ode.html#e1"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#numerical.ode.e1" title="Permalink to this definition"></a></dt>
<dd><p>Explicit first-order method /
@@ -235,7 +219,8 @@ Euler-Cauchy-Verfahren / Euler-vorwärts-Verfahren</p>
<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>*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>
@@ -247,12 +232,12 @@ 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>The derivative of the solution is approximated as the forward difference
equation</p>
<p>The derivative of the solution is approximated as the forward
difference equation</p>
<div class="math notranslate nohighlight">
\[\dot{x}_i = f(t_i, x_i) = \frac{x_{i+1} - x_i}{t_{i+1}-t_i}\]</div>
<p>Therefore 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>
<p>Therefore 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>
@@ -272,7 +257,8 @@ x_2 &amp;= \dot{u} &amp;\quad \dot{x}_2 = \ddot{u} \\\end{split}\]</div>
<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}(f(t) - d x_2 - k x_1) \end{bmatrix} \\
\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}
@@ -288,19 +274,24 @@ 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>
\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} \\
\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}
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
<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>
@@ -314,7 +305,8 @@ proportional to the step size.</p>
<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>*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>
@@ -331,7 +323,8 @@ proportional to the step size.</p>
<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>*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>
@@ -339,30 +332,37 @@ proportional to the step size.</p>
</dd></dl>
<dl class="function">
<dt id="numerical.ode.fixed_point_iteration">
<code class="descname">fixed_point_iteration</code><span class="sig-paren">(</span><em>f</em>, <em>xi</em>, <em>t</em>, <em>max_iterations=1000</em>, <em>tol=1e-09</em>, <em>verbose=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/numerical/ode.html#fixed_point_iteration"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#numerical.ode.fixed_point_iteration" title="Permalink to this definition"></a></dt>
<dd><dl class="field-list simple">
<dt id="numerical.ode.fpi">
<code class="descname">fpi</code><span class="sig-paren">(</span><em>f</em>, <em>xi</em>, <em>ti</em>, <em>ti1</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="reference internal" href="_modules/numerical/ode.html#fpi"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#numerical.ode.fpi" title="Permalink to this definition"></a></dt>
<dd><p>Fixed-point iteration.</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 iterate <span class="math notranslate nohighlight">\(f = \Delta{x}(t)\)</span></p></li>
<li><p><strong>f</strong> (<em>function</em>) the function to iterate <span class="math notranslate nohighlight">\(f = \dot{x}(x,t)\)</span></p></li>
<li><p><strong>xi</strong> (<em>list</em>) initial condition <span class="math notranslate nohighlight">\(x_i\)</span></p></li>
<li><p><strong>t</strong> (<em>float</em>) time <span class="math notranslate nohighlight">\(t\)</span></p></li>
<li><p><strong>*p</strong> parameters of the function (thickness, diameter, …)</p></li>
<li><p><strong>ti</strong> (<em>float</em>) time <span class="math notranslate nohighlight">\(t_i\)</span></p></li>
<li><p><strong>ti1</strong> (<em>float</em>) time <span class="math notranslate nohighlight">\(t_{i+1}\)</span></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>tol</strong> (<em>float</em>) tolerance against residuum <span class="math notranslate nohighlight">\(\varepsilon\)</span>
(default = 1e-9)</p></li>
<li><p><strong>verbose</strong> (<em>bool</em>) print information (default = False)</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p><span class="math notranslate nohighlight">\(x_{i+1}\)</span></p>
<dd class="field-even"><p><span class="math notranslate nohighlight">\(x_{i}\)</span></p>
</dd>
</dl>
<div class="math notranslate nohighlight">
\[x_{i+1} = x_i + \Delta x\]</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<p><a class="reference internal" href="#numerical.ode.dxdt_Dt" title="numerical.ode.dxdt_Dt"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dxdt_Dt()</span></code></a> for <span class="math notranslate nohighlight">\(\Delta x\)</span></p>
</div>
\[x_{i,j=0} = x_{i}\]</div>
<div class="math notranslate nohighlight">
\[x_{i,j+1} = x_i + \dot{x}(x_{i,j}, t_{i+1})\cdot(t_{i+1}-t_i)\]</div>
<div class="math notranslate nohighlight">
\[\text{residuum} = \frac{\lVert x_{i,j+1}-x_{i,j}\rVert}
{\lVert x_{i,j+1} \rVert} &lt; \varepsilon\]</div>
<div class="math notranslate nohighlight">
\[x_{i} = x_{i,j=\text{end}}\]</div>
</dd></dl>
<dl class="function">
@@ -375,7 +375,8 @@ proportional to the step size.</p>
<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>*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>
@@ -385,11 +386,6 @@ proportional to the step size.</p>
<p>The backward Euler method has order one and is A-stable.</p>
</dd></dl>
<dl class="function">
<dt id="numerical.ode.i1n">
<code class="descname">i1n</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="reference internal" href="_modules/numerical/ode.html#i1n"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#numerical.ode.i1n" title="Permalink to this definition"></a></dt>
<dd></dd></dl>
<dl class="function">
<dt id="numerical.ode.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="reference internal" href="_modules/numerical/ode.html#newmark_newtonraphson"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#numerical.ode.newmark_newtonraphson" title="Permalink to this definition"></a></dt>
@@ -402,7 +398,8 @@ proportional to the step size.</p>
<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>*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>
@@ -415,7 +412,7 @@ proportional to the step size.</p>
<dl class="function">
<dt id="numerical.ode.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="reference internal" href="_modules/numerical/ode.html#newmark_newtonraphson_rdk"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#numerical.ode.newmark_newtonraphson_rdk" title="Permalink to this definition"></a></dt>
<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>max_iterations=1000</em>, <em>tol=1e-09</em>, <em>verbose=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/numerical/ode.html#newmark_newtonraphson_rdk"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#numerical.ode.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>
@@ -425,7 +422,8 @@ proportional to the step size.</p>
<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>*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>