pyCBD.preprocessing.butcher module

This module contains a class to construct butcher tableaus and a set of predefined tables.

class pyCBD.preprocessing.butcher.ButcherTableau(rows=None, weights=None)[source]

Bases: object

Mnemonic device to store the Runge-Kutta matrix, weights and nodes in the computation of generic RK methods. The extended tableau also allows for the error computation for adaptive step sizes. The general form of a Butcher Tableau is shown below, where:

  • \(s\) identifies the number of stages;

  • \(a_{ij}, 1 \leq j < i \leq s\) represents a coefficient in the Runge-Kutta matrix;

  • \(b_i\) and \(b^*_i\) correspond to the weights of a higher and a lower order method, respectively; and

  • \(c_i\) specifies the nodes.

\[\begin{split}\begin{array} {c|ccccc} 0\\ c_2 & a_{2,1}\\ c_3 & a_{3,1} & a_{3,2} \\ \vdots & \vdots & & \ddots\\ c_s & a_{s,1} & a_{s,2} & \cdots & a_{s,s-1}\\ \hline & b_1 & b_2 & \cdots & b_{s-1} & b_s\\ & b^*_1 & b^*_2 & \cdots & b^*_{s-1} & b^*_s\\ \end{array}\end{split}\]
Parameters
  • rows (iter) – Sequence of tuples \((c_i, [a_{i, j}\vert 1 \leq j < i])\). When None, nothing will be added.

  • weights (iter) – Sequence of sequences of weights \([b_{i}\vert i \leq s]\). When None, no weights will be added.

Note

Upon instantiation, the first (empty) row will be added automatically with a node of 0.

addRow(node, elems)[source]

Adds a \(c_i\) and \(a_{i, j}\) to the tableau.

Parameters
  • node (numeric) – The \(c_i\)-value.

  • elems (iter) – \(a_{i, j}\), \(\forall j < i\); i.e. the sequence of matrix elements that correspond to the node.

addWeights(*weights)[source]

Adds a row of weights to the bottom of the matrix.

Parameters

*weights – A sequence of the weights. I.e. \(b_{i}\), where \(1 \leq i \leq s\).

getNodes()[source]

Obtains the nodes, i.e. the \(c_i\)-values.

getWeights()[source]

Obtains the weight lists, i.e. the \(b_i\) and \(b^*_i\)-values.

getA(i, j)[source]

Obtains an element from the Runge-Kutta matrix.

Parameters
  • i (int) – The row (1-indexed).

  • j (int) – The column (1-indexed).

getOrder(wix=- 1)[source]

Computes the order of the Tableau. The order is the amount of non-zero weights.

Parameters

wix (id) – The weight index. Defaults to -1 (i.e. the last weight row of the tableau).

static Euler()[source]

Creates and returns the Butcher Tableau for Euler’s method. The Tableau is as follows:

\[\begin{split}\begin{array} {c|cc} 0\\ \hline & 1 \end{array}\end{split}\]
static Heun()[source]

Creates and returns the Butcher Tableau for Heun’s method. The Tableau is as follows:

\[\begin{split}\begin{array} {c|cc} 0\\ 1 & 1\\ \hline & 1/2 & 1/2 \end{array}\end{split}\]
static HeunEuler()[source]

Creates and returns the extended Butcher Tableau for Heun’s method, combined with the Euler method. The Tableau is as follows:

\[\begin{split}\begin{array} {c|cc} 0\\ 1 & 1\\ \hline & 1/2 & 1/2\\ & 1 & 0 \end{array}\end{split}\]
static Ralston()[source]

Creates and returns the Butcher Tableau for Ralston’s method for 2nd order accuracy. The Tableau is as follows:

\[\begin{split}\begin{array} {c|cc} 0\\ 2/3 & 2/3\\ \hline & 1/4 & 3/4 \end{array}\end{split}\]
static RalstonEuler()[source]

Creates and returns the extended Butcher Tableau for Ralston’s method, combined with the Euler method. The Tableau is as follows:

\[\begin{split}\begin{array} {c|cc} 0\\ 2/3 & 2/3\\ \hline & 1/4 & 3/4\\ & 1 & 0 \end{array}\end{split}\]
static Midpoint()[source]

Creates and returns the Butcher Tableau for the midpoint method. The Tableau is as follows:

\[\begin{split}\begin{array} {c|cc} 0\\ 1/2 & 1/2\\ \hline & 0 & 1 \end{array}\end{split}\]
static MidpointEuler()[source]

Creates and returns the extended Butcher Tableau for the midpoint method, combined with the Euler method. The Tableau is as follows:

\[\begin{split}\begin{array} {c|cc} 0\\ 1/2 & 1/2\\ \hline & 0 & 1\\ & 1 & 0 \end{array}\end{split}\]
static RK4()[source]

Creates and returns the Butcher Tableau for the default RK algorithm. The Tableau is as follows:

\[\begin{split}\begin{array} {c|cc} 0\\ 1/2 & 1/2\\ 1/2 & 0 & 1/2\\ 1 & 0 & 0 & 1\\ \hline & 1/6 & 1/3 & 1/3 & 1/6 \end{array}\end{split}\]
static RK4Alt()[source]

Creates and returns the Butcher Tableau for an alternative RK algorithm. It is also called the 3/8-rule. The Tableau is as follows:

\[\begin{split}\begin{array} {c|cc} 0\\ 1/3 & 1/3\\ 2/3 & -1/3 & 1\\ 1 & 1 & -1 & 1\\ \hline & 1/8 & 3/8 & 3/8 & 1/8 \end{array}\end{split}\]
static RKF45()[source]

Creates and returns the extended Butcher Tableau for the Runge-Kutta-Fehlberg algorithm of 4th and 5th order. The Tableau is as follows:

\[\begin{split}\begin{array} {c|cc} 0\\ 1/4 & 1/4\\ 3/8 & 3/32 & 9/32\\ 12/13 & 1932/2197 & -7200/2197 & 7296/2197\\ 1 & 439/216 & -8 & 3680/513 & -845/4104\\ 1/2 & -8/27 & 2 & -3544/2565 & 1859/4104 & -11/40\\ \hline & 16/135 & 0 & 6656/12825 & 28561/56430 & -9/50 & 2/55\\ & 25/216 & 0 & 1408/2565 & 2197/4104 & -1/5 & 0 \end{array}\end{split}\]
static DOPRI()[source]

Creates and returns the extended Butcher Tableau for the Dormand-Prince method. This is the default method in the ode45 solver for MATLAB and GNU Octave, among others. The Tableau is as follows:

\[\begin{split}\begin{array} {c|cc} 0\\ 1/5 & 1/5\\ 3/10 & 3/40 & 9/40\\ 4/5 & 44/45 & -56/15 & 32/9\\ 8/9 & 19372/6561 & -25360/2187 & 64448/6561 & -212/729\\ 1 & 9017/3168 & -355/33 & 46732/5247 & 49/176 & -5103/18656\\ 1 & 35/384 & 0 & 500/1113 & 125/192 & -2187/6784 & 11/84\\ \hline & 35/384 & 0 & 500/1113 & 125/192 & -2187/6784 & 11/84 & 0\\ & 5179/57600 & 0 & 7571/16695 & 393/640 & -92097/339200 & 187/2100 & 1/40 \end{array}\end{split}\]
static RKDP()

Alias of DOPRI().

static DormandPrince()

Alias of DOPRI().

static RKCK()[source]

Creates and returns the extended Butcher Tableau for the Cash-Karp method for 4th and 5th order accurate solutions. The Tableau is as follows:

\[\begin{split}\begin{array} {c|cc} 0\\ 1/5 & 1/5\\ 3/10 & 3/40 & 9/40\\ 3/5 & 3/10 & -9/10 & 6/5\\ 1 & -11/54 & 5/2 & -70/27 & 35/27\\ 7/8 & 1631/55296 & 175/512 & 575/13824 & 44275/110592 & 253/4096\\ \hline & 37/378 & 0 & 250/621 & 125/594 & 0 & 512/1771\\ & 2825/27648 & 0 & 18575/48384 & 13525/55296 & 277/14336 & 1/4 \end{array}\end{split}\]
static CashKarp()

Alias of RKCK().

static BogackiShampine()[source]

Creates and returns the extended Butcher Tableau for the Bogacki-Shampine method for 3th order accurate solutions.

It is implemented in the ode23 function in MATLAB.

The Tableau is as follows:

\[\begin{split}\begin{array} {c|cc} 0\\ 1/2 & 1/2\\ 3/4 & 0 & 3/4\\ 1 & 2/9 & 1/3 & 4/9\\ \hline & 2/9 & 1/3 & 4/9 & 0\\ & 7/24 & 1/4 & 1/3 & 1/8 \end{array}\end{split}\]