API reference

Numa.LinearSystem

numa.LinearSystem.solveGauss(A, b)[source]

Solves the given linear system of equations using the Gauss method. A post-iteration is implemented as well to reduce the error.

Parameters
  • A (numpy.arrays) – Coefficient matrix

  • b (numpy.array) – Column vector of constant terms

Returns

x – Solution vector

Return type

numpy.array

Notes

The pivot element for the i-th row in the i-th column is choosen through

\[a_p = max_{k=i,...,n}|a_{ki}|\]

Rounding errors can lead to less accurate results so

\[A \cdot (x + \Delta x) = b + \Delta b\]

is calculated instead. This can be rewritten

\[\Delta b = A \cdot (x + \Delta x) - b\]
\[A \cdot \Delta x = \Delta b\]
\[x_0 = (x + \Delta x)\]
\[x_1 = x_0 - \Delta x\]

numa.LinearSystem.solveLU(A, b)[source]

Solves the given linear system of equations using LU decomposition. A post-iteration is implemented as well to reduce the error.

Parameters
  • A (numpy.arrays) – Coefficient matrix

  • b (numpy.array) – Column vector of constant terms

Returns

x – Solution vector

Return type

numpy.array


numa.LinearSystem.LU(A)[source]

Decompose the given coefficient matrix into a lower and upper triangular matrix L and U so that

\[A = L \cdot U\]
Parameters

A (numpy.arrays) – Matrix

Returns

L, U – Lower and upper triangular matrix.

Return type

numpy.arrays

Notes

The decomposition is calculated using Doolittle’s method.

\[l_{ii} = 1\]
\[u_{ij} = a_{ij} - \sum_{k=1}^{i-1}l_{ik}u_{kj}\]
\[l_{ji} = u_{ii}^{-1}(a_{ij} - \sum_{k=1}^{i-1}l_{jk}u_{ki})\]

numa.LinearSystem.condition(A, p)[source]

Calculate the condition number of the input Matrix using the numpy function.

Parameters
  • A (numpy.arrays) – Input matrix whose condition number is sought

  • p ({None, 1, -1, 2, -2, inf, -inf, 'fro'}) – Order of the norm

Returns

c – Condition number of the matrix. May be infinite.

Return type

float


Numa.RootFinder

numa.RootFinder.preAnalysis1D(function, interval_start, interval_end)[source]

Approximate possible roots of a given one-parameter function and the given domain. This function creates a numpy.linspace and calculates all possible values on that domain. The function is assumed to be continuous and not positive definit axial symmetric with respect to the y axis in that case. Positions where the sign of the function value changes will be marked as a possible root area and returned. This method should not be used to approximate roots. It should rather be a tool to further define the domain space for methods like numa.RootFinder.bisection.

Parameters
  • function (callable, (e.g f = lambda x: x**2)) – Function to analyze.

  • interval_start (int) – lower limit of the domain

  • interval_end (int) – upper limit of the domain

Returns

A list of all x values that are in the near area of a root.

Return type

list


numa.RootFinder.NewtonRhapson(function, x0, Dfunction=None, max_iterations=10000, giveIterations=False)[source]

Approximate one root of a given one-parameter function using the Newton-Rhapson method; note that this method can converge very rapidly with a very good initial value for x0. Though a bad value for x0 can make it impossible to find due to endless cycling between the same points or due to an escape to infinity.

Parameters
  • function (callable) – Function to analyze.

  • x0 (float) – Initial guess of root value

  • Dfunction (callable, optional) – Derivative function of the given one-parameter-function

  • max_iterations (int) – Maximum number of iterations until the loop breaks. Default set to 10000

  • giveIterations (boolean, optional) – Information whether the value for iterations needed and the error should be returned or not. Lists starts at iteration two since the error is always calculated with respect to the previous guess.

Returns

(root value, error, convergence)

Return type

tuple

Notes

Calculates the next x-intercept of the tangent line recursively

\[x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)}\]

References

[1] https://www.math.ubc.ca/~pwalls/math-python/roots-optimization/newton/


numa.RootFinder.bisection(function, interval_start, interval_end, max_iterations=10000, giveIterations=False)[source]

Approximate one root of a given one-parameter function using the Bisection method; note that the root has to be inside the interval or the bisection method won’t yield any results. This method can only return one of the possible roots if multiple exist.

Parameters
  • function (callable) – Function to analyze.

  • interval_start (int) – lower limit of the domain

  • interval_end (int) – upper limit of the domain

  • max_iterations (int) – Maximum number of iterations until the loop breaks. Default set to 10000

  • giveIterations (boolean, optional) – Information whether the value for iterations needed and the error should be returned or not. Lists starts at iteration two since the error is always calculated with respect to the previous guess.

Returns

(root value, error, convergence)

Return type

tuple

Notes

Calculates the midpoint after every iteration as

\[m_N = \frac{a_N + b_N}{2}\]

References

[1] https://www.math.ubc.ca/~pwalls/math-python/roots-optimization/bisection/


numa.RootFinder.secant(function, interval_start, interval_end, max_iterations=10000, giveIterations=False)[source]

Approximate one root of a given one-parameter function using the secant method;

Parameters
  • function (callable) – Function to analyze.

  • interval_start (int) – lower limit of the domain

  • interval_end (int) – upper limit of the domain

  • max_iterations (int) – Maximum number of iterations until the loop breaks. Default set to 10000

  • giveIterations (boolean, optional) – Information whether the value for iterations needed and the error should be returned or not. Lists starts at iteration two since the error is always calculated with respect to the previous guess.

Returns

(root value, error, convergence)

Return type

tuple

Notes

Calculates the next upper limit for the interval as

\[x_k = \frac{af(b) - bf(a)}{f(b)-f(a)} \Longrightarrow [b_n, x_k]\]

numa.RootFinder.regulaFalsi(function, interval_start, interval_end, max_iterations=10000, giveIterations=False)[source]

Approximate one root of a given one-parameter function using the Regula Falsi method; note that the root has to be inside the interval or the method won’t yield any results. This method can only return one of the possible roots if multiple exist and is generally not used due to it’s unstable nature.

Parameters
  • function (callable) – Function to analyze.

  • interval_start (int) – lower limit of the domain

  • interval_end (int) – upper limit of the domain

  • max_iterations (int) – Maximum number of iterations until the loop breaks. Default set to 10000

  • giveIterations (boolean, optional) – Information whether the value for iterations needed and the error should be returned or not. Lists starts at iteration two since the error is always calculated with respect to the previous guess.

Returns

(root value, error, convergence)

Return type

tuple

Notes

Calculates the next upper limit for the interval as

\[x_k = \frac{af(b) - bf(a)}{f(b)-f(a)} \Longrightarrow [a_n, x_k] \quad \text{or} \quad [x_k, b_n]\]

but chooses the next interval based on the position of x_k.


Numa.utils

numa.utils.inverse(A)[source]

Calculates the inverse matrix of A such that

\[A \cdot A^{-1} = I\]
Parameters

A (numpy.arrays) – Matrix

Returns

inverseA – Inverse matrix of A

Return type

numpy.arrays


numa.utils.det(A)[source]

Returns determinant of A.

Parameters

A (numpy.arrays) – Matrix

Returns

D – Determinant

Return type

numpy.arrays

Notes

Currently this function is only calling the numpy function under the hood until the LU problems are fixed.


numa.utils.isSingular(A)[source]

Checks if matrix A is singular or not.

Parameters

A (numpy.arrays) – Matrix

Returns

T,F – True if matrix is singular, False if not.

Return type

boolean

Notes

Currently only checks determinant.


Numa.Integrate