mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-03-13 09:50:19 +08:00
The black formatter is no longer beta (#5960)
* The black formatter is no longer beta
* pre-commit autoupdate
* pre-commit autoupdate
* Remove project_euler/problem_145 which is killing our CI tests
* updating DIRECTORY.md
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@@ -32,7 +32,7 @@ def bisection(function: Callable[[float], float], a: float, b: float) -> float:
|
||||
raise ValueError("could not find root in given interval.")
|
||||
else:
|
||||
mid: float = start + (end - start) / 2.0
|
||||
while abs(start - mid) > 10 ** -7: # until precisely equals to 10^-7
|
||||
while abs(start - mid) > 10**-7: # until precisely equals to 10^-7
|
||||
if function(mid) == 0:
|
||||
return mid
|
||||
elif function(mid) * function(start) < 0:
|
||||
@@ -44,7 +44,7 @@ def bisection(function: Callable[[float], float], a: float, b: float) -> float:
|
||||
|
||||
|
||||
def f(x: float) -> float:
|
||||
return x ** 3 - 2 * x - 5
|
||||
return x**3 - 2 * x - 5
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -23,7 +23,7 @@ def polar_force(
|
||||
|
||||
|
||||
def in_static_equilibrium(
|
||||
forces: ndarray, location: ndarray, eps: float = 10 ** -1
|
||||
forces: ndarray, location: ndarray, eps: float = 10**-1
|
||||
) -> bool:
|
||||
"""
|
||||
Check if a system is in equilibrium.
|
||||
|
||||
@@ -35,7 +35,7 @@ def intersection(function: Callable[[float], float], x0: float, x1: float) -> fl
|
||||
x_n2: float = x_n1 - (
|
||||
function(x_n1) / ((function(x_n1) - function(x_n)) / (x_n1 - x_n))
|
||||
)
|
||||
if abs(x_n2 - x_n1) < 10 ** -5:
|
||||
if abs(x_n2 - x_n1) < 10**-5:
|
||||
return x_n2
|
||||
x_n = x_n1
|
||||
x_n1 = x_n2
|
||||
|
||||
@@ -37,17 +37,17 @@ def newton(
|
||||
next_guess = prev_guess - function(prev_guess) / derivative(prev_guess)
|
||||
except ZeroDivisionError:
|
||||
raise ZeroDivisionError("Could not find root") from None
|
||||
if abs(prev_guess - next_guess) < 10 ** -5:
|
||||
if abs(prev_guess - next_guess) < 10**-5:
|
||||
return next_guess
|
||||
prev_guess = next_guess
|
||||
|
||||
|
||||
def f(x: float) -> float:
|
||||
return (x ** 3) - (2 * x) - 5
|
||||
return (x**3) - (2 * x) - 5
|
||||
|
||||
|
||||
def f1(x: float) -> float:
|
||||
return 3 * (x ** 2) - 2
|
||||
return 3 * (x**2) - 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -11,7 +11,7 @@ from sympy import diff
|
||||
|
||||
|
||||
def newton_raphson(
|
||||
func: str, a: float | Decimal, precision: float = 10 ** -10
|
||||
func: str, a: float | Decimal, precision: float = 10**-10
|
||||
) -> float:
|
||||
"""Finds root from the point 'a' onwards by Newton-Raphson method
|
||||
>>> newton_raphson("sin(x)", 2)
|
||||
|
||||
Reference in New Issue
Block a user