Non-linear Equations
This module includes root-finding algorithms and numerical solvers for non-linear equations.
Gauss_elimination_pivoted(matrix, vector)
Function for Gaussian elimination using partial pivoting to reduce numerical errors.
Swaps rows to ensure the largest absolute value in the current column becomes the pivot element, minimizing floating-point inaccuracies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
ndarray
|
Coefficient matrix. |
required |
vector
|
ndarray
|
Right-hand side vector. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
x |
ndarray
|
Solution vector. |
Source code in openum/NonLinEq.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
bisection_method(x1, x2, f, max_iter, eps=1e-06)
Solving nonlinear equations with bisection method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1
|
float
|
Lower bound of the interval. |
required |
x2
|
float
|
Upper bound of the interval. |
required |
f
|
function
|
Function for which the root is to be found. |
required |
max_iter
|
int
|
Maximum number of iterations. |
required |
eps
|
float
|
Convergence criterion. |
1e-06
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Approximation of the root, or None if no convergence. |
Source code in openum/NonLinEq.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
jacobi_method(A, b, init_val, max_iter, tol=1e-06)
Solve a linear system using the iterative Jacobi method.
In contrast to Gauss-Seidel, the Jacobi method uses only the values from the previous iteration step to calculate the new approximations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
A
|
ndarray
|
Coefficient matrix. |
required |
b
|
ndarray
|
Right-hand side vector. |
required |
init_val
|
list
|
Initial guess for the solution vector x. |
required |
max_iter
|
int
|
Maximum number of iterations. |
required |
tol
|
float
|
Convergence tolerance. |
1e-06
|
Returns:
| Type | Description |
|---|---|
ndarray
|
numpy.ndarray: Solution vector if convergence is achieved. |
Source code in openum/NonLinEq.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
linear_interpolation(f, x0, x1, max_iter, epsilon=1e-06)
Find the root of a function using linear interpolation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
function
|
Function for which the root is to be found. |
required |
x0
|
float
|
Initial guess. |
required |
x1
|
float
|
Second guess. |
required |
max_iter
|
int
|
Maximum number of iterations. |
required |
epsilon
|
float
|
Convergence criterion. |
1e-06
|
Returns:
| Name | Type | Description |
|---|---|---|
x2 |
float
|
Approximation of the root, or None if no convergence. |
Source code in openum/NonLinEq.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
newton_halley(f, df, d2f, x0, max_iter, epsilon=1e-06)
Find the root of a function using Newton-Halley method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
function
|
Function for which the root is to be found. |
required |
df
|
function
|
First derivative of the function. |
required |
d2f
|
function
|
Second derivative of the function. |
required |
x0
|
float
|
Initial guess. |
required |
max_iter
|
int
|
Maximum number of iterations. |
required |
epsilon
|
float
|
Convergence criterion. |
1e-06
|
Returns:
| Name | Type | Description |
|---|---|---|
x |
float
|
Approximation of the root, or None if no convergence. |
Source code in openum/NonLinEq.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
newtons_method(f, df, x0, max_iter, epsilon=1e-06)
Find the root of a function using Newton's method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
function
|
Function for which the root is to be found. |
required |
df
|
function
|
Derivative of the function. |
required |
x0
|
float
|
Initial guess. |
required |
max_iter
|
int
|
Maximum number of iterations. |
required |
epsilon
|
float
|
Convergence criterion. |
1e-06
|
Returns:
| Name | Type | Description |
|---|---|---|
x |
float
|
Approximation of the root, or None if no convergence. |
Source code in openum/NonLinEq.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
solve_fixed_point(f1, f2, x_init, y_init, max_iter, tol=1e-08)
Solve a system of equations using fixed-point iteration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f1
|
function
|
Function for the first equation. |
required |
f2
|
function
|
Function for the second equation. |
required |
x_init
|
float
|
Initial guess for x. |
required |
y_init
|
float
|
Initial guess for y. |
required |
max_iter
|
int
|
Maximum number of iterations. |
required |
tol
|
float
|
Convergence criterion. |
1e-08
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[float, float]
|
Approximations of the roots (x, y), or (None, None) if no convergence. |
Source code in openum/NonLinEq.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |