示例#1
0
def get_index_from_key(key, j, n):
    r"""
    Return first occurrence of given key over a Kronecker power.

    INPUT:

    - ``key`` -- list or tuple, key corresponding to the exponent vector in the
      Kronecker power

    - ``j`` -- integer, order of the Kronecker power

    - ``n`` -- integer, number of dimensions

    NOTES:

    - We assume `n \geq 2`. Notice that if `n=1`, we would return always that ``first_occurence = 0``.

    EXAMPLES:

    Take `x^{[2]}` for `x=(x_1, x_2)` and compute retrive the first ocurrence of
    the given key::

        sage: from carlin.transformation import get_index_from_key
        sage: get_index_from_key([1, 1], 2, 2)
        1
    """
    x = polygens(QQ, ['x' + str(1 + k) for k in range(n)])
    x_power_j = kron_power(x, j)

    for i, monomial in enumerate(x_power_j):
        if (list(monomial.dict().keys()[0]) == key):
            first_occurence = i
            break

    return first_occurence
示例#2
0
def cubic_scalar(a=1, b=1):
    r"""
    A scalar ODE with a cubic term.
    
    It is defined as:

    .. MATH::

        x'(t) = ax(t) + bx(t)^3

    where `a` and `b` are paremeters of the ODE.

    EXAMPLES::

        sage: from carlin.library import cubic_scalar
        sage: C = cubic_scalar(-1, 1)
        sage: C.funcs()
        [x0^3 - x0]

    Compute the Carleman embedding truncated at order `N=4`::

        sage: from carlin.transformation import get_Fj_from_model, truncated_matrix 
        sage: Fj = get_Fj_from_model(C.funcs(), C.dim(), C.degree())
        sage: matrix(truncated_matrix(4, *Fj, input_format="Fj_matrices").toarray())
        [-1.0  0.0  1.0  0.0]
        [ 0.0 -2.0  0.0  2.0]
        [ 0.0  0.0 -3.0  0.0]
        [ 0.0  0.0  0.0 -4.0]
    """
    # define the vector of symbolic variables
    x = polygens(QQ, ['x0'])
    f = [None] * 1
    f[0] = a * x[0] + b * x[0]**3
    return PolynomialODE(f, n=1, k=3)
示例#3
0
def get_key_from_index(i, j, n):
    r"""
    Return multi-index of Kronecker power given an index and the order.

    INPUT:

    - ``i`` -- integer, index in the canonial Kronecker power enumeration

    - ``j`` -- integer, order of the Kronecker power

    - ``n`` -- integer, number of dimensions

    EXAMPLES:

    Take `x^{[2]}` for `x=(x_1, x_2)` and compute the exponent vector of the element
    in position `1`::

        sage: from carlin.transformation import get_key_from_index
        sage: get_key_from_index(1, 2, 2)
        [1, 1]
    """
    x = polygens(QQ, ['x' + str(1 + k) for k in range(n)])
    x_power_j = kron_power(x, j)
    d = x_power_j[i].dict()
    return list(d.items()[0][0])
示例#4
0
def chen_seven_dim(u=0):
    r"""
    This is a seven-dimensional nonlinear system of quadratic order.

    It appears as ``'example_nonlinear_reach_04_sevenDim_nonConvexRepr.m'`` in 
    the tool CORA 2016, in the examples for continuous nonlinear systems.

    .. NOTE:

    There is an independent term, `u`, in the fourth equation with value `2.0` that has
    been neglected here for convenience (hence we take `u=0` by default).
    """
    # dimension of state-space
    n = 7

    # vector of variables
    x = polygens(QQ, ['x' + str(i) for i in range(n)])

    f = [None] * n

    f[0] = 1.4 * x[2] - 0.9 * x[0]
    f[1] = 2.5 * x[4] - 1.5 * x[1]
    f[2] = 0.6 * x[6] - 0.8 * x[2] * x[1]
    f[3] = -1.3 * x[3] * x[2] + u
    f[4] = 0.7 * x[0] - 1.0 * x[3] * x[4]
    f[5] = 0.3 * x[0] - 3.1 * x[5]
    f[6] = 1.8 * x[5] - 1.5 * x[6] * x[1]

    return PolynomialODE(f, n, k=2)
示例#5
0
def biomodel_2():
    r"""
    This is a nine-dimensional polynomial ODE used as benchmark model in
    `the Flow star tool <https://ths.rwth-aachen.de/research/projects/hypro/biological-model-ii/>`_.

    The model is adapted from E. Klipp, R. Herwig, A. Kowald, C. Wierling, H. Lehrach.
    Systems Biology in Practice: Concepts, Implementation and Application. Wiley-Blackwell, 2005.
    """
    # dimension of state-space
    n = 9

    # vector of variables
    x = polygens(QQ, ['x' + str(i) for i in range(n)])

    f = [None] * n
    f[0] = 3 * x[2] - x[0] * x[5]
    f[1] = x[3] - x[1] * x[5]
    f[2] = x[0] * x[5] - 3 * x[2]
    f[3] = x[1] * x[5] - x[3]
    f[4] = 3 * x[2] + 5 * x[0] - x[4]
    f[5] = 5 * x[4] + 3 * x[2] + x[3] - x[5] * (x[0] + x[1] + 2 * x[7] + 1)
    f[6] = 5 * x[3] + x[1] - 0.5 * x[6]
    f[7] = 5 * x[6] - 2 * x[5] * x[7] + x[8] - 0.2 * x[7]
    f[8] = 2 * x[5] * x[7] - x[8]

    return PolynomialODE(f, n, k=2)
示例#6
0
def arrowsmith_and_place_fig_3_5e_page_79():
    r"""
    Nonlinear two-dimensional system with an hyperbolic fixed point.

    It is defined as:

    .. MATH::

        \begin{aligned}
         x' &= x^2+(x+y)/2 \\
         y' &= (-x+3y)/2
        \end{aligned}

    Taken from p. 79 of the book by Arrowsmith and Place, Dynamical Systems:
    Differential Equations, maps and chaotic behaviour.
    """
    # dimension of state-space
    n = 2

    # vector of variables
    x = polygens(QQ, ['x' + str(i) for i in range(n)])

    # ODE and order k=2
    f = [x[0]**2 + (x[0] + x[1]) / 2, (-x[0] + 3 * x[1]) / 2]

    return PolynomialODE(f, n, k=2)
示例#7
0
def quadratic_scalar(a=1, b=1):
    r"""
    A scalar ODE with a quadratic term.

    It is defined as:

    .. MATH::

        x'(t) = ax(t) + bx(t)^2

    where `a` and `b` are paremeters of the ODE.

    EXAMPLES::

        sage: from carlin.library import quadratic_scalar
        sage: Q = quadratic_scalar(); Q
        A Polynomial ODE in n = 1 variables
        sage: Q.funcs()
        [x0^2 + x0]

    Compute the Carleman embedding truncated at order `N=4`::

        sage: from carlin.transformation import get_Fj_from_model, truncated_matrix 
        sage: Fj = get_Fj_from_model(Q.funcs(), Q.dim(), Q.degree())
        sage: matrix(truncated_matrix(4, *Fj, input_format="Fj_matrices").toarray())
        [1.0 1.0 0.0 0.0]
        [0.0 2.0 2.0 0.0]
        [0.0 0.0 3.0 3.0]
        [0.0 0.0 0.0 4.0]
    """
    # define the vector of symbolic variables
    x = polygens(QQ, ['x0'])
    f = [None] * 1
    f[0] = a * x[0] + b * x[0]**2
    return PolynomialODE(f, 1, 2)
示例#8
0
def vanderpol(mu=1, omega=1):
    r"""
    The Van der Pol oscillator is a non-conservative system with non-linear damping.
    
    It is defined as:

    .. MATH::

        \begin{aligned}
        x' &= y \\
        y' &= -\omega^2  x - (x^2 - 1) \mu y
        \end{aligned}

    where `\omega` is the natural frequency and `\mu` is the damping parameter.
    For additional information see the :wikipedia:`Van_der_Pol_oscillator`.

    EXAMPLES::

        sage: from carlin.library import vanderpol
        sage: vanderpol(SR.var('mu'), SR.var('omega')).funcs()
        [x1, -omega^2*x0 - (x0^2 - 1)*mu*x1]
    """
    # dimension of state-space
    n = 2

    # define the vector of symbolic variables
    x = polygens(QQ, ['x' + str(i) for i in range(n)])

    # vector field (n-dimensional)
    f = [None] * n

    f[0] = x[1]
    f[1] = -omega**2 * x[0] + mu * (1 - x[0]**2) * x[1]

    # the order is k=3
    return PolynomialODE(f, n, k=3)