i am just analysing a C Implementation of my Algorithm vs the Matlab-Algorithm. It works quite fine, exceptionally when it Comes to calculate the square root of a complex number.
I tried already 3 different implementations on how to calculate a complex square root in C, but None of this implementation Matches the matlab result.
The Problem is, that the sign of the imaginary parts differs from my implementation. Here are two examples:
I tried to pick the principal square root, which is the one with the positive real part. This works for the first example, but not for the second case.
I Need to have the same result as calculated by matlab.
Thanks in Advance!
EDIT:
I am trying to get all cases correct by the following Code
Is this correct?
EDIT2:
I have collected some test cases. It seems the sign of the imaginary part always remain unchanged:
EDIT3: Found this in the sqrt-doc of matlab: