

def 		SCREAMING_SNAKE_CASE__					(				_UpperCAmelCase,   _UpperCAmelCase					)       ->			float:



    '''simple docstring'''






    if density <= 0:
        raise ValueError('Impossible fluid density'					)
    if bulk_modulus <= 0:
        raise ValueError('Impossible bulk modulus'					)

    return (bulk_modulus / density) ** 0.5


if __name__ == "__main__":
 import doctest

 doctest.testmod()












"""simple docstring"""


import numpy as np




def        lowercase__     (       lowercase_		,lowercase_		,lowercase_ = 1e-12		,lowercase_ = 100		,)       ->		tuple[float, np.ndarray]:




      """simple docstring"""

      assert np.shape(lowercase_      )[0] == np.shape(lowercase_      )[1]
      # Ensure proper dimensionality.
      assert np.shape(lowercase_      )[0] == np.shape(lowercase_      )[0]
      # Ensure inputs are either both complex or both real
      assert np.iscomplexobj(lowercase_      ) == np.iscomplexobj(lowercase_      )
      _UpperCamelCase   :						Dict    =							np.iscomplexobj(lowercase_      )
      if is_complex:
            # Ensure complex input_matrix is Hermitian
            assert np.array_equal(lowercase_		,input_matrix.conj().T      )

      # Set convergence to False. Will define convergence when we exceed max_iterations
      # or when we have small changes from one iteration to next.

      _UpperCamelCase   :						List[Any]    =							False
      _UpperCamelCase   :						Optional[int]    =							0
      _UpperCamelCase   :						int    =							0
      _UpperCamelCase   :						Optional[int]    =							1e12

      while not convergence:
            # Multiple matrix by the vector.
            _UpperCamelCase   :						Optional[int]    =							np.dot(lowercase_		,lowercase_      )
            # Normalize the resulting output vector.
            _UpperCamelCase   :						List[Any]    =							w / np.linalg.norm(lowercase_      )
            # Find rayleigh quotient
            # (faster than usual b/c we know vector is normalized already)
            _UpperCamelCase   :						Optional[Any]    =							vector.conj().T if is_complex else vector.T
            _UpperCamelCase   :						Dict    =							np.dot(lowercase_		,np.dot(lowercase_		,lowercase_      )      )

            # Check convergence.
            _UpperCamelCase   :						Optional[int]    =							np.abs(lambda_ - lambda_previous      ) / lambda_
            iterations += 1

            if error <= error_tol or iterations >= max_iterations:
                  _UpperCamelCase   :						List[Any]    =							True

            _UpperCamelCase   :						Tuple    =							lambda_

      if is_complex:
            _UpperCamelCase   :						Tuple    =							np.real(lambda_      )

      return lambda_, vector




def        lowercase__     (       )       ->		None:




      """simple docstring"""

      _UpperCamelCase   :						Dict    =							np.array([[41, 4, 20], [4, 26, 30], [20, 30, 50]]      )
      _UpperCamelCase   :						Optional[int]    =							np.array([41, 4, 20]      )
      _UpperCamelCase   :						Union[str, Any]    =							real_input_matrix.astype(np.complexaaa      )
      _UpperCamelCase   :						int    =							np.triu(1J * complex_input_matrix		,1      )
      complex_input_matrix += imag_matrix
      complex_input_matrix += -1 * imag_matrix.T
      _UpperCamelCase   :						Union[str, Any]    =							np.array([41, 4, 20]      ).astype(np.complexaaa      )

      for problem_type in ["real", "complex"]:
            if problem_type == "real":
                  _UpperCamelCase   :						Dict    =							real_input_matrix
                  _UpperCamelCase   :						Any    =							real_vector
            elif problem_type == "complex":
                  _UpperCamelCase   :						int    =							complex_input_matrix
                  _UpperCamelCase   :						Union[str, Any]    =							complex_vector

            # Our implementation.
            _UpperCamelCase,	_UpperCamelCase   :						int    =							power_iteration(lowercase_		,lowercase_      )

            # Numpy implementation.

            # Get eigenvalues and eigenvectors using built-in numpy
            # eigh (eigh used for symmetric or hermetian matrices).
            _UpperCamelCase,	_UpperCamelCase   :						str    =							np.linalg.eigh(lowercase_      )
            # Last eigenvalue is the maximum one.
            _UpperCamelCase   :						Any    =							eigen_values[-1]
            # Last column in this matrix is eigenvector corresponding to largest eigenvalue.
            _UpperCamelCase   :						Tuple    =							eigen_vectors[:, -1]

            # Check our implementation and numpy gives close answers.
            assert np.abs(eigen_value - eigen_value_max      ) <= 1e-6
            # Take absolute values element wise of each eigenvector.
            # as they are only unique to a minus sign.
            assert np.linalg.norm(np.abs(lowercase_      ) - np.abs(lowercase_      )      ) <= 1e-6


if __name__ == "__main__":
  import doctest

  doctest.testmod()
  test_power_iteration()
