Skip to content

Commit c615011

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 42d68d9 commit c615011

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

maths/numerical_analysis/fixed_point_iteration.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from typing import Callable
22

3+
34
def fixed_point_iteration(
45
iteration_function: Callable[[float], float],
56
initial_guess: float,
67
tolerance: float = 1e-7,
7-
max_iterations: int = 1000
8+
max_iterations: int = 1000,
89
) -> float:
910
"""
1011
Perform Fixed Point Iteration to find the root of the equation x = g(x).
@@ -38,11 +39,12 @@ def fixed_point_iteration(
3839
x = x_new
3940
raise ValueError("Fixed Point Iteration did not converge")
4041

42+
4143
if __name__ == "__main__":
4244

4345
def quadratic_transform(current_value: float) -> float:
4446
"""Quadratic transformation function for iteration."""
4547
return (current_value**2 + 2) / 3
4648

4749
root = fixed_point_iteration(quadratic_transform, initial_guess=1.0)
48-
print(f"Approximate root: {root}")
50+
print(f"Approximate root: {root}")

maths/numerical_analysis/modified_newton_raphson.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from typing import Callable
22

3+
34
def modified_newton_raphson(
45
function: Callable[[float], float],
56
derivative_function: Callable[[float], float],
67
initial_guess: float,
78
tolerance: float = 1e-7,
8-
max_iterations: int = 1000
9+
max_iterations: int = 1000,
910
) -> float:
1011
"""
1112
Perform the Modified Newton-Raphson method to find the root of f(x) = 0.
@@ -47,6 +48,7 @@ def modified_newton_raphson(
4748
x = x_new
4849
raise ValueError("Modified Newton-Raphson did not converge")
4950

51+
5052
if __name__ == "__main__":
5153
import math
5254

@@ -56,5 +58,7 @@ def compute_function(current_x: float) -> float:
5658
def compute_derivative(current_x: float) -> float:
5759
return 3 * current_x**2 - 2
5860

59-
root = modified_newton_raphson(compute_function, compute_derivative, initial_guess=2.0)
60-
print(f"Approximate root: {root}")
61+
root = modified_newton_raphson(
62+
compute_function, compute_derivative, initial_guess=2.0
63+
)
64+
print(f"Approximate root: {root}")

0 commit comments

Comments
 (0)