


'''simple docstring'''
import unittest

import numpy as np


def     a   (    __a				,      __a				,      __a				,      __a = None				,      )						->			Optional[int]:



					'''simple docstring'''






					UpperCamelCase__     :List[str]							      =				np.shape(a_     )
					UpperCamelCase__     :str							      =				np.shape(a_     )
					UpperCamelCase__     :int							      =				np.shape(a_     )

					if shape_a[0] != shape_b[0]:
										UpperCamelCase__     :Union[str, Any]							      =				(
										    '''Expected the same number of rows for A and B. '''
										    f'''Instead found A of size {shape_a} and B of size {shape_b}'''
										)
										raise ValueError(a_     )

					if shape_b[1] != shape_c[1]:
										UpperCamelCase__     :int							      =				(
										    '''Expected the same number of columns for B and C. '''
										    f'''Instead found B of size {shape_b} and C of size {shape_c}'''
										)
										raise ValueError(a_     )

					UpperCamelCase__     :List[str]							      =				pseudo_inv
					if a_inv is None:
										try:
															UpperCamelCase__     :Tuple							      =				np.linalg.inv(a_     )
										except np.linalg.LinAlgError:
															raise ValueError(
															    '''Input matrix A is not invertible. Cannot compute Schur complement.'''     )

					return mat_c - mat_b.T @ a_inv @ mat_b
class      lowercase			(							unittest.TestCase      ):

		"""simple docstring"""

		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Tuple							      =				np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]							)
							UpperCamelCase__     :List[str]							      =				np.array([[0, 3], [3, 0], [2, 3]]							)
							UpperCamelCase__     :List[Any]							      =				np.array([[2, 1], [6, 3]]							)

							UpperCamelCase__     :List[Any]							      =				schur_complement(__snake_case					,     __snake_case					,     __snake_case							)

							UpperCamelCase__     :Union[str, Any]							      =				np.block([[a, b], [b.T, c]]							)

							UpperCamelCase__     :List[Any]							      =				np.linalg.det(__snake_case							)
							UpperCamelCase__     :Optional[int]							      =				np.linalg.det(__snake_case							)
							UpperCamelCase__     :str							      =				np.linalg.det(__snake_case							)

							self.assertAlmostEqual(__snake_case					,     det_a * det_s							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Dict							      =				np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]							)
							UpperCamelCase__     :Optional[int]							      =				np.array([[0, 3], [3, 0], [2, 3]]							)
							UpperCamelCase__     :Tuple							      =				np.array([[2, 1], [6, 3]]							)

							with self.assertRaises(__snake_case							):
												schur_complement(__snake_case					,     __snake_case					,     __snake_case							)




		def 					lowerCAmelCase__       (	self							):

							'''simple docstring'''


							UpperCamelCase__     :Any							      =				np.array([[1, 2, 1], [2, 1, 2], [3, 2, 4]]							)
							UpperCamelCase__     :Optional[Any]							      =				np.array([[0, 3], [3, 0], [2, 3]]							)
							UpperCamelCase__     :Optional[Any]							      =				np.array([[2, 1, 3], [6, 3, 5]]							)

							with self.assertRaises(__snake_case							):
												schur_complement(__snake_case					,     __snake_case					,     __snake_case							)


if __name__ == "__main__":
						import doctest

						doctest.testmod()
						unittest.main()



'''simple docstring'''
import numpy as np


def     a   (    __a				,      __a				,      __a				,      __a				,      __a     )						->			Union[str, Any]:



					'''simple docstring'''






					UpperCamelCase__     :Tuple							      =				int(np.ceil((x_end - xa) / h     )     )
					UpperCamelCase__     :Optional[int]							      =				np.zeros((n + 1,)     )
					UpperCamelCase__     :List[str]							      =				ya
					UpperCamelCase__     :Tuple							      =				xa

					for k in range(__a     ):
										UpperCamelCase__     :Dict							      =				f(__a				,      y[k]     )
										UpperCamelCase__     :List[Any]							      =				f(x + 0.5 * h				,      y[k] + 0.5 * h * ka     )
										UpperCamelCase__     :Dict							      =				f(x + 0.5 * h				,      y[k] + 0.5 * h * ka     )
										UpperCamelCase__     :List[Any]							      =				f(x + h				,      y[k] + h * ka     )
										UpperCamelCase__     :List[str]							      =				y[k] + (1 / 6) * h * (ka + 2 * ka + 2 * ka + ka)
										x += h

					return y


if __name__ == "__main__":
		import doctest

		doctest.testmod()