Imports and notebook configuration

In [1]:
from matplotlib import rcdefaults
rcdefaults()  # restore default matplotlib rc parameters
%config InlineBackend.figure_format='retina'   
import seaborn as sns  # wrapper for matplotlib that provides prettier styles and more
import matplotlib.pyplot as plt  # use matplotlib functionality directly
%matplotlib inline   
sns.set()

import numpy as np

import sympy as sp
sp.init_printing()

Multistep methods

Generating the formulas

In [18]:
def generate_lmf(lmin_alpha, k, lmin_beta, lmax_beta):
    #k = max( lmax_alpha, lmax_beta )
    # create the unknowns
    alpha = [0]*(k+1)
    beta  = [0]*(k+1)

    varlist = []
    alpha[k] = 1   # w.o.l.o.g.
    for i in range(lmin_alpha,k): 
        alpha[i] = sp.symbols(f'alpha_{i}')
        varlist.append(alpha[i])
    for i in range(lmin_beta ,lmax_beta+1):
        beta[i]  = sp.symbols(f'beta_{i}')
        varlist.append(beta[i])
    nfree = len(varlist)
    display(alpha)
    display(beta)
    display(nfree)
    display(varlist)

    # build the equations
    c = [sum(alpha)]
    for q in range(1,nfree):
        c.append( sum( [ l**q    *alpha[l]/sp.factorial(q)
                        -l**(q-1)* beta[l]/sp.factorial(q-1) for l in range(k+1) ] ) )
    for item in c:
        display(item)

    sol = sp.solve(c,varlist)
    display(sol)
    
    alpha = [ sol[item] if item in sol else item for item in alpha ]
    beta  = [ sol[item] if item in sol else item for item in beta  ]
    return alpha, beta
In [19]:
generate_lmf(4,5,0,4)
$\displaystyle \left[ 0, \ 0, \ 0, \ 0, \ \alpha_{4}, \ 1\right]$
$\displaystyle \left[ \beta_{0}, \ \beta_{1}, \ \beta_{2}, \ \beta_{3}, \ \beta_{4}, \ 0\right]$
$\displaystyle 6$
$\displaystyle \left[ \alpha_{4}, \ \beta_{0}, \ \beta_{1}, \ \beta_{2}, \ \beta_{3}, \ \beta_{4}\right]$
$\displaystyle \alpha_{4} + 1$
$\displaystyle 4 \alpha_{4} - \beta_{0} - \beta_{1} - \beta_{2} - \beta_{3} - \beta_{4} + 5$
$\displaystyle 8 \alpha_{4} - \beta_{1} - 2 \beta_{2} - 3 \beta_{3} - 4 \beta_{4} + \frac{25}{2}$
$\displaystyle \frac{32 \alpha_{4}}{3} - \frac{\beta_{1}}{2} - 2 \beta_{2} - \frac{9 \beta_{3}}{2} - 8 \beta_{4} + \frac{125}{6}$
$\displaystyle \frac{32 \alpha_{4}}{3} - \frac{\beta_{1}}{6} - \frac{4 \beta_{2}}{3} - \frac{9 \beta_{3}}{2} - \frac{32 \beta_{4}}{3} + \frac{625}{24}$
$\displaystyle \frac{128 \alpha_{4}}{15} - \frac{\beta_{1}}{24} - \frac{2 \beta_{2}}{3} - \frac{27 \beta_{3}}{8} - \frac{32 \beta_{4}}{3} + \frac{625}{24}$
$\displaystyle \left\{ \alpha_{4} : -1, \ \beta_{0} : \frac{251}{720}, \ \beta_{1} : - \frac{637}{360}, \ \beta_{2} : \frac{109}{30}, \ \beta_{3} : - \frac{1387}{360}, \ \beta_{4} : \frac{1901}{720}\right\}$
Out[19]:
$\displaystyle \left( \left[ 0, \ 0, \ 0, \ 0, \ -1, \ 1\right], \ \left[ \frac{251}{720}, \ - \frac{637}{360}, \ \frac{109}{30}, \ - \frac{1387}{360}, \ \frac{1901}{720}, \ 0\right]\right)$
In [ ]:
adams bashforth methods
In [3]:
[1,2]+[3,4,5]
Out[3]:
$\displaystyle \left[ 1, \ 2, \ 3, \ 4, \ 5\right]$
In [4]:
[77]*5
Out[4]:
$\displaystyle \left[ 77, \ 77, \ 77, \ 77, \ 77\right]$
In [5]:
[0]*10
Out[5]:
$\displaystyle \left[ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0, \ 0\right]$
In [ ]: