




import math as m



def     lowerCAmelCase		(		_lowerCAmelCase				: Union[str, Any]    ,				_lowerCAmelCase				: List[Any]    ,				_lowerCAmelCase				: Optional[int]=0.001						):




 """simple docstring"""







 return (f(a + h						) - f(a - h						)) / (2 * h)



def     lowerCAmelCase		(		_lowerCAmelCase				: Any    ,				_lowerCAmelCase				: Union[str, Any]=0    ,				_lowerCAmelCase				: Union[str, Any]=100    ,				_lowerCAmelCase				: Optional[Any]=0.0_001    ,				_lowerCAmelCase				: Dict=1E-6    ,				_lowerCAmelCase				: Dict=False						):




 """simple docstring"""







 UpperCAmelCase__							=    xa  # set the initial guess
 UpperCAmelCase__							=    [a]
 UpperCAmelCase__							=    abs(f(_lowerCAmelCase						)						)
 UpperCAmelCase__							=    lambda _lowerCAmelCase						: calc_derivative(_lowerCAmelCase    ,				_lowerCAmelCase    ,				h=_lowerCAmelCase						)  # noqa: E731  Derivative of f(x)
 for _ in range(_lowerCAmelCase						):
  if fa(_lowerCAmelCase						) == 0:
   raise ValueError("No converging solution found"						)
  UpperCAmelCase__							=    a - f(_lowerCAmelCase						) / fa(_lowerCAmelCase						)  # Calculate the next estimate
  if logsteps:
   steps.append(_lowerCAmelCase						)
  if error < maxerror:
   break
 else:
  raise ValueError("Iteration limit reached, no converging solution found"						)
 if logsteps:
  # If logstep is true, then log intermediate steps
  return a, error, steps
 return a, error


if __name__ == "__main__":
  from matplotlib import pyplot as plt

  _lowerCAmelCase    : str		= lambda x: m.tanh(x) ** 2 - m.exp(3 * x)  # noqa: E731
  _lowerCAmelCase,       _lowerCAmelCase,       _lowerCAmelCase    : Optional[Any]		= newton_raphson(
      f, xa=1_0, maxiter=1_0_0_0, step=1E-6, logsteps=True
  )
  plt.plot([abs(f(x)) for x in steps])
  plt.xlabel("step")
  plt.ylabel("error")
  plt.show()
  print(F'''solution = {{{solution:f}}}, error = {{{error:f}}}''')











from math import cos, sin



def     lowerCAmelCase		(		_lowerCAmelCase				: float						):




 """simple docstring"""







 UpperCAmelCase__							=    float(_lowerCAmelCase						)
 return [[scaling_factor * int(x == y						) for x in range(2						)] for y in range(2						)]



def     lowerCAmelCase		(		_lowerCAmelCase				: float						):




 """simple docstring"""







 UpperCAmelCase__			,			UpperCAmelCase__							=    cos(_lowerCAmelCase						), sin(_lowerCAmelCase						)
 return [[c, -s], [s, c]]



def     lowerCAmelCase		(		_lowerCAmelCase				: float						):




 """simple docstring"""







 UpperCAmelCase__			,			UpperCAmelCase__							=    cos(_lowerCAmelCase						), sin(_lowerCAmelCase						)
 UpperCAmelCase__							=    c * s
 return [[c * c, cs], [cs, s * s]]



def     lowerCAmelCase		(		_lowerCAmelCase				: float						):




 """simple docstring"""







 UpperCAmelCase__			,			UpperCAmelCase__							=    cos(_lowerCAmelCase						), sin(_lowerCAmelCase						)
 UpperCAmelCase__							=    c * s
 return [[2 * c - 1, 2 * cs], [2 * cs, 2 * s - 1]]


print(F'''    {scaling(5) = }''')
print(F'''  {rotation(4_5) = }''')
print(F'''{projection(4_5) = }''')


print(F'''{reflection(4_5) = }''')





