mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-25 10:28:39 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
cde2acb872
commit
baa524385a
@ -7,9 +7,7 @@ from __future__ import annotations
|
|||||||
from sympy import diff, symbols, sympify
|
from sympy import diff, symbols, sympify
|
||||||
|
|
||||||
|
|
||||||
def newton_raphson(
|
def newton_raphson(func: str, a: float, precision: float = 10**-10) -> float:
|
||||||
func: str, a: float, precision: float = 10**-10
|
|
||||||
) -> float:
|
|
||||||
"""Finds root from the point 'a' onwards by Newton-Raphson method
|
"""Finds root from the point 'a' onwards by Newton-Raphson method
|
||||||
>>> newton_raphson("sin(x)", 2)
|
>>> newton_raphson("sin(x)", 2)
|
||||||
3.1415926536808043
|
3.1415926536808043
|
||||||
@ -21,9 +19,13 @@ def newton_raphson(
|
|||||||
2.718281828458938
|
2.718281828458938
|
||||||
"""
|
"""
|
||||||
x = a
|
x = a
|
||||||
symbol = symbols('x')
|
symbol = symbols("x")
|
||||||
exp = sympify(func) # expressions to be represented symbolically and manipulated algebraically
|
exp = sympify(
|
||||||
exp_diff = diff(exp, symbol) # calculates the derivative value at the current x value
|
func
|
||||||
|
) # expressions to be represented symbolically and manipulated algebraically
|
||||||
|
exp_diff = diff(
|
||||||
|
exp, symbol
|
||||||
|
) # calculates the derivative value at the current x value
|
||||||
maximum_iterations = 100
|
maximum_iterations = 100
|
||||||
|
|
||||||
for _ in range(maximum_iterations):
|
for _ in range(maximum_iterations):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user