From 0e47fdd5fb97da65bc211b83ce1c3f8cabf3b985 Mon Sep 17 00:00:00 2001 From: jan Date: Tue, 9 Jan 2018 00:00:58 -0800 Subject: [PATCH] randomize imaginary part of starting vector --- fdfd_tools/bloch.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fdfd_tools/bloch.py b/fdfd_tools/bloch.py index ea9e760..168a349 100644 --- a/fdfd_tools/bloch.py +++ b/fdfd_tools/bloch.py @@ -422,24 +422,24 @@ def eigsolve(num_modes: int, prev_E = 0 d_scale = 1 prev_traceGtKG = 0 - prev_theta = 0.5 + #prev_theta = 0.5 D = numpy.zeros(shape=y_shape, dtype=complex) y0 = None if y0 is None: - Z = numpy.random.rand(*y_shape).astype(complex) + Z = numpy.random.rand(*y_shape) + 1j * numpy.random.rand(*y_shape) else: Z = y0 while True: - Z2 = Z.conj().T @ Z - Z_norm = numpy.sqrt(real(trace(Z2))) / num_modes + ZtZ = Z.conj().T @ Z + Z_norm = numpy.sqrt(real(trace(ZtZ))) / num_modes Z /= Z_norm - Z2 /= Z_norm * Z_norm + ZtZ /= Z_norm * Z_norm try: - U = numpy.linalg.inv(Z2) + U = numpy.linalg.inv(ZtZ) except numpy.linalg.LinAlgError: - Z = numpy.random.rand(*y_shape).astype(complex) + Z = numpy.random.rand(*y_shape) + 1j * numpy.random.rand(*y_shape) continue trace_U = real(trace(U)) @@ -565,7 +565,7 @@ def eigsolve(num_modes: int, Z += D * numpy.sin(theta) prev_traceGtKG = traceGtKG - prev_theta = theta + #prev_theta = theta prev_E = E '''