linear_algebra.jacobi_iteration_method

Jacobi Iteration Method - https://en.wikipedia.org/wiki/Jacobi_method

Functions

jacobi_iteration_method(→ list[float])

Jacobi Iteration Method:

strictly_diagonally_dominant(→ bool)

Module Contents

linear_algebra.jacobi_iteration_method.jacobi_iteration_method(coefficient_matrix: numpy.typing.NDArray[numpy.float64], constant_matrix: numpy.typing.NDArray[numpy.float64], init_val: list[float], iterations: int) list[float]

Jacobi Iteration Method: An iterative algorithm to determine the solutions of strictly diagonally dominant system of linear equations

4x1 + x2 + x3 = 2

x1 + 5x2 + 2x3 = -6 x1 + 2x2 + 4x3 = -4

x_init = [0.5, -0.5 , -0.5]

Examples:

>>> coefficient = np.array([[4, 1, 1], [1, 5, 2], [1, 2, 4]])
>>> constant = np.array([[2], [-6], [-4]])
>>> init_val = [0.5, -0.5, -0.5]
>>> iterations = 3
>>> jacobi_iteration_method(coefficient, constant, init_val, iterations)
[0.909375, -1.14375, -0.7484375]
>>> coefficient = np.array([[4, 1, 1], [1, 5, 2]])
>>> constant = np.array([[2], [-6], [-4]])
>>> init_val = [0.5, -0.5, -0.5]
>>> iterations = 3
>>> jacobi_iteration_method(coefficient, constant, init_val, iterations)
Traceback (most recent call last):
    ...
ValueError: Coefficient matrix dimensions must be nxn but received 2x3
>>> coefficient = np.array([[4, 1, 1], [1, 5, 2], [1, 2, 4]])
>>> constant = np.array([[2], [-6]])
>>> init_val = [0.5, -0.5, -0.5]
>>> iterations = 3
>>> jacobi_iteration_method(
...     coefficient, constant, init_val, iterations
... )  
Traceback (most recent call last):
    ...
ValueError: Coefficient and constant matrices dimensions must be nxn and nx1 but
            received 3x3 and 2x1
>>> coefficient = np.array([[4, 1, 1], [1, 5, 2], [1, 2, 4]])
>>> constant = np.array([[2], [-6], [-4]])
>>> init_val = [0.5, -0.5]
>>> iterations = 3
>>> jacobi_iteration_method(
...     coefficient, constant, init_val, iterations
... )  
Traceback (most recent call last):
    ...
ValueError: Number of initial values must be equal to number of rows in coefficient
            matrix but received 2 and 3
>>> coefficient = np.array([[4, 1, 1], [1, 5, 2], [1, 2, 4]])
>>> constant = np.array([[2], [-6], [-4]])
>>> init_val = [0.5, -0.5, -0.5]
>>> iterations = 0
>>> jacobi_iteration_method(coefficient, constant, init_val, iterations)
Traceback (most recent call last):
    ...
ValueError: Iterations must be at least 1
linear_algebra.jacobi_iteration_method.strictly_diagonally_dominant(table: numpy.typing.NDArray[numpy.float64]) bool
>>> table = np.array([[4, 1, 1, 2], [1, 5, 2, -6], [1, 2, 4, -4]])
>>> strictly_diagonally_dominant(table)
True
>>> table = np.array([[4, 1, 1, 2], [1, 5, 2, -6], [1, 2, 3, -4]])
>>> strictly_diagonally_dominant(table)
Traceback (most recent call last):
    ...
ValueError: Coefficient matrix is not strictly diagonally dominant