mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-14 11:33:42 +02:00
Added test_complex_matrix_inverse
This commit is contained in:
parent
157fc1058a
commit
abdff600e6
1 changed files with 23 additions and 0 deletions
|
@ -18,6 +18,29 @@ def test_matrix_inverse():
|
|||
assert all([o.is_zero() for o in np.diag(matrix) * np.diag(inverse_matrix) - 1])
|
||||
|
||||
|
||||
def test_complex_matrix_inverse():
|
||||
dimension = 6
|
||||
base_matrix = np.empty((dimension, dimension), dtype=object)
|
||||
matrix = np.empty((dimension, dimension), dtype=complex)
|
||||
for (n, m), entry in np.ndenumerate(base_matrix):
|
||||
exponent_real = np.random.normal(3, 5)
|
||||
exponent_imag = np.random.normal(3, 5)
|
||||
base_matrix[n, m] = pe.CObs(pe.pseudo_Obs(2 + 10 ** exponent_real, 10 ** (exponent_real - 1), 't'),
|
||||
pe.pseudo_Obs(2 + 10 ** exponent_imag, 10 ** (exponent_imag - 1), 't'))
|
||||
|
||||
# Construct invertible matrix
|
||||
obs_matrix = np.identity(dimension) + base_matrix @ base_matrix.T
|
||||
|
||||
for (n, m), entry in np.ndenumerate(obs_matrix):
|
||||
matrix[n, m] = entry.real.value + 1j * entry.imag.value
|
||||
|
||||
inverse_matrix = np.linalg.inv(matrix)
|
||||
inverse_obs_matrix = pe.linalg.mat_mat_op(np.linalg.inv, obs_matrix)
|
||||
for (n, m), entry in np.ndenumerate(inverse_matrix):
|
||||
assert np.isclose(inverse_matrix[n, m].real, inverse_obs_matrix[n, m].real.value)
|
||||
assert np.isclose(inverse_matrix[n, m].imag, inverse_obs_matrix[n, m].imag.value)
|
||||
|
||||
|
||||
def test_matrix_functions():
|
||||
dim = 3 + int(4 * np.random.rand())
|
||||
print(dim)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue