MATLAB: Zeros of a complex surface

complexsurfacezeros

I have a complex matrix Z (evolving in time) and would like to know at which points both the real and the imaginary part of Z are null. I can do it graphically using the following code:
figure
set(gca,'fontsize',16)
for k = 1:size(T)
cla;
contour(HI0,HR0,real(Z{k}),[0,0],'b.')
hold on
contour(HI0,HR0,imag(Z{k}),[0,0],'r.')
hold on
legend(strcat('Re(Z): T=',num2str(T(k))),strcat('Im(Z): T=',num2str(T(k))));
xlabel H_I
ylabel H_R
pause(0.5);
end
which shows the intersections of the isocurves Re(Z)=0 and Im(Z)=0, but I am stuck here. If I take abs(Z), I am afraid not to get all the zeros.
Thanks a lot!

Best Answer

sr = sign(real(Z));
si = sign(imag(Z));
zerohorz_r = (sr(:,1:end-1) .* sr(:,2:end)) <= 0;
zerohorz_i = (si(:,1:end-1) .* si(:,2:end)) <= 0;
zerohorz = zerohorz_r & zerohorz_i;
zerovert_r = (sr(1:end-1,:) .* sr(2:end,:)) <= 0;
zerovert_i = (si(1:end-1,:) .* si(2:end,:)) <= 0;
zerovert = zerovert_r & zerovert_i;
zerohorz(J,K) is true if in looking at Z(J,K) compared to Z(J,K+1), the real and imaginary components both changed sign, or one changed sign and the other is 0, or both are zero. If, for example, the real component changed sign from positive to negative, but the imaginary component did not change sign, then that is not considered to be a zero crossing.
zerovert(J,K) is the corresponding test, but for Z(J,K) compared to Z(J+1,K)
Note that these matrices are one column narrower or one row shorter than the original, since they deal with zero crossing in-between points.
The logic here:
  • if the signs of two items are both +1 or both -1, then their product is +1, and this corresponds to the case where no zero crossing was made.
  • if the signs of two items are -1 and +1, or +1 and -1, then their product is -1, and this corresponds to the case where a zero crossing was definitely made.
  • if the signs of two items are both 0, then their product is 0. No crossing was made, but they are both 0, and you are looking for the zeros, not for the crossings as such
  • if the signs are +1 and 0, or -1 and 0, or 0 and +1, or 0 and -1, then their product is 0. No crossing was made, but at least one of them was a 0. If you had a sequence such as +1, 0, -1, then the code would detect mark both of them; it would also mark both sites for a +1, 0, +1. You might want to refine which "direction" the zero needs to be approached from for your purposes.