# loki.analyse.util_linear_algebra

Functions

`back_substitution`(...[, divison_operation]) | Solve a linear system of equations using back substitution for an upper triangular square matrix.
`generate_row_echelon_form`(A[, ...]) | Calculate the Row Echelon Form (REF) of a matrix.
`is_independent_system`(matrix) | Check if a linear system of equations can be split into independent one-dimensional problems.
`yield_one_d_systems`(matrix, right_hand_side) | Split a linear system of equations (<=, >=, or ==) into independent one-dimensional problems.

back_substitution(upper_triangular_square_matrix, right_hand_side, divison_operation=<function <lambda>>)

  Solve a linear system of equations using back substitution for an upper triangular square matrix.

  Parameters:

    - upper_triangular_square_matrix (numpy.ndarray) – An upper triangular square matrix (R).

    - right_hand_side (numpy.ndarray) – A vector (y) on the right-hand side of the equation Rx = y.

    - division_operation (function, optional) – A custom division operation function. Default is standard division (/).

  Returns:

    The solution vector (x) to the system of equations Rx = y.

  Return type:

    numpy.ndarray

  Notes

  The function performs back substitution to find the solution vector x for the equation Rx = y, where R is an upper triangular square matrix and y is a vector. The division_operation function is used for division (e.g., for custom division operations).

  The function assumes that the upper right element of the upper_triangular_square_matrix (R) is nonzero for proper back substitution.

generate_row_echelon_form(A, conditional_check=<function <lambda>>, division_operator=<function <lambda>>)

  Calculate the Row Echelon Form (REF) of a matrix.

  Parameters:

    - A (numpy.ndarray) – The input matrix for which the REF is to be calculated.

    - conditional_check (function, optional) – A custom function to check conditions during the computation.

    - division_operation (function, optional) – A custom division operation function. Default is standard division (/).

  Returns:

    The REF of the input matrix A.

  Return type:

    numpy.ndarray

  Notes

  - If the input matrix has no rows or columns, it is already in REF, and the function returns itself.

  - The function utilizes the specified division operation (default is standard division) for division.

  ## Reference

  https://math.stackexchange.com/a/3073117 for question: https://math.stackexchange.com/questions/3073083/how-to-reduce-matrix-into-row-echelon-form-in-numpy

is_independent_system(matrix)

  Check if a linear system of equations can be split into independent one-dimensional problems.

  Parameters:

    matrix (numpy.ndarray) – A rectangular matrix representing coefficients.

  Returns:

    True if the system can be split into independent one-dimensional problems, False otherwise.

  Return type:

    bool

  Notes

  This function checks whether a linear system of equations in the form of matrix [operator] right_hand_side can be split into independent one-dimensional problems. The number of problems is determined by the number of variables (the row number of the matrix).

  Each problem consists of a coefficient vector and a right-hand side. The system can be considered independent if each row of the matrix has exactly one non-zero coefficient or no non-zero coefficients.

yield_one_d_systems(matrix, right_hand_side)

  Split a linear system of equations (<=, >=, or ==) into independent one-dimensional problems.

  Parameters:

    - matrix (numpy.ndarray) – A rectangular matrix representing coefficients.

    - right_hand_side (numpy.ndarray) – The right-hand side vector.

  Yields:

    tuple[numpy.ndarray, numpy.ndarray] – A tuple containing a coefficient vector and the corresponding right-hand side.

  Notes

  The independence of the problems is NOT explicitly checked; call is_independent_system before using this function if unsure.

  This function takes a linear system of equations in the form of matrix [operator] right_hand_side, where “matrix” is a rectangular matrix, “x” is a vector of variables, and “right_hand_side” is the right-hand side vector. It splits the system into assumed independent one-dimensional problems.

  Each problem consists of a coefficient vector and a right-hand side. The number of problems is equal to the number of variables (the row number of the matrix).

  Example

      for A, b in yield_one_d_systems(matrix, right_hand_side):
          # Solve the one-dimensional problem A * x = b
          solution = solve_one_d_system(A, b)