






"""simple docstring"""

from sympy import diff, lambdify, symbols
from sympy.functions import *  # noqa: F403

def 		__lowerCamelCase	(  __UpperCamelCase      ,       __UpperCamelCase      ,       __UpperCamelCase = "x"      ,       __UpperCamelCase = 10**-10      ,       __UpperCamelCase = 1      ,       )						->    complex:

		"""simple docstring"""







		lowerCAmelCase_   :							Any									=			symbols(a_       )
		lowerCAmelCase_   :							List[Any]									=			lambdify(a_      ,       a_       )
		lowerCAmelCase_   :							List[str]									=			lambdify(a_      ,       diff(a_      ,       a_       )       )

		lowerCAmelCase_   :							Any									=			starting_point

		while True:
				if diff_function(a_       ) != 0:
						lowerCAmelCase_   :							str									=			prev_guess - multiplicity * func(a_       ) / diff_function(
						    a_       )
				else:
						raise ZeroDivisionError("Could not find root"       ) from None

				# Precision is checked by comparing the difference of consecutive guesses
				if abs(next_guess - prev_guess       ) < precision:
						return next_guess

				lowerCAmelCase_   :							str									=			next_guess


# Let's Execute
if __name__ == "__main__":
					# Find root of trigonometric function
					# Find value of pi
					print(F"""The root of sin(x) = 0 is {newton_raphson('sin(x)', 2)}""")

					# Find root of polynomial
					# Find fourth Root of 5
					print(F"""The root of x**4 - 5 = 0 is {newton_raphson('x**4 -5', 0.4 +5J)}""")

					# Find value of e
					print(
					    """The root of log(y) - 1 = 0 is """,
					    F"""{newton_raphson('log(y) - 1', 2, variable='y')}""",
					)

					# Exponential Roots
					print(
					    """The root of exp(x) - 1 = 0 is""",
					    F"""{newton_raphson('exp(x) - 1', 10, precision=0.005)}""",
					)

					# Find root of cos(x)
					print(F"""The root of cos(x) = 0 is {newton_raphson('cos(x)', 0)}""")







"""simple docstring"""
from collections.abc import Callable

import numpy as np



def      __lowerCamelCase   (							a_     :		Callable ,   a_     :		float ,   a_     :		float ,   a_     :		float ,   a_     :		float							)			->      np.ndarray:
      __SCREAMING_SNAKE_CASE   :List[Any]						=  int(np.ceil((x_end - xa) / step_size							)							)
      __SCREAMING_SNAKE_CASE   :Optional[Any]						=  np.zeros((n + 1,)							)
      __SCREAMING_SNAKE_CASE   :int						=  ya
      __SCREAMING_SNAKE_CASE   :str						=  xa

      for k in range(a_							):
            __SCREAMING_SNAKE_CASE   :Optional[int]						=  y[k] + step_size * ode_func(a_ ,   y[k]							)
            x += step_size

      return y


if __name__ == "__main__":
  import doctest

  doctest.testmod()