Utilities Module

Contents

modespy.util.newton_const

Solve system of equations using a Newton-Raphson iteration with a constant Jacobian term computed only on the first iteration.

modespy.util.pad_coeffs

Return polynomial coefficients coeffs with the higher order end padded with rows of zero to suit requested higher order target_p.

modespy.util.polyval_cols

Evaluate multiple polynomials as columns of p, using the same value x each time.

Members

Utility functions used in various places by MODESpy.

Differences to MATLAB Implementation

  • (Version 0.9.0) Convergence check of modified Newton-Raphson method has been changed. Refer to newton_const() source code for details.

modespy.util.newton_const(fun, x0, *, jac, args=(), tol=1e-06, options=None)

Solve system of equations using a Newton-Raphson iteration with a constant Jacobian term computed only on the first iteration. This function is designed to be called in an identical fashion as root() in scipy.optimise.

Parameters:
  • fun (callable) – A function f(x, *args) that takes a vector argument, and returns a value of the same length.

  • x0 (ndarray) – The starting estimate for the root of fun(x) = 0.

  • jac (array_like or callable) –

    Jacobian matrix of the right-hand side of the system. The Jacobian matrix has shape (n, n) and element (i, j) is equal to \(df_i/dy_j\):

    • If array-like: It is assumed to be a constant matrix.

    • If callable, the Jacobian is assumed to depend on both t and y; it will be called once-only as jac(t, y).

  • args (tuple, optional) – Any extra arguments to fun.

  • tol (float) – The calculation will terminate if the infinity norm of the last correction step was less than tol (default = 1e-6).

  • options (dict, optional) –

    A dictionary of solver options. Available options are:
    ’maxiter’int

    The maximum number of iterations / calls to the function (default = 50).

Returns:

  • Bunched object with the following fields

  • x (ndarray) – Solution vector.

  • success (bool) – True if the solution was found within required tolerance and number of iterations.

  • status (int) –

    • 0: The solver finished successfully.

    • 1: The number of calls to f(x) has reached maxfev.

  • message (str) – Verbose description of the status.

  • nfev (int) – Number of function (RHS) evaluations.

  • njev (int) – Number of Jacobian evaluations.

  • nit (int) – Number of iterations of the solver.

modespy.util.pad_coeffs(coeffs: ndarray, target_p: int) ndarray

Return polynomial coefficients coeffs with the higher order end padded with rows of zero to suit requested higher order target_p.

modespy.util.polyval_cols(p: ndarray, x: float)

Evaluate multiple polynomials as columns of p, using the same value x each time. Returns an array of the results.