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!

댓글 수: 2

Michelangelo Ricciulli
Michelangelo Ricciulli 2017년 3월 7일
So you need to separately find where the real part and imaginary part are exactly zero,right?
Matthieu Michel
Matthieu Michel 2017년 3월 8일
That was my idea. But how can I then get the intersection of the isocurves real(Z)=0 and imag(Z)=0?

댓글을 달려면 로그인하십시오.

 채택된 답변

Walter Roberson
Walter Roberson 2017년 3월 8일

3 개 추천

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.

추가 답변 (1개)

John BG
John BG 2017년 3월 7일
편집: John BG 2017년 3월 7일

0 개 추천

wrong approach,
people take abs(Z)==0 to solve the problem mentioned in your question PRECISELY because whem real(Z)==0 && imag(Z)==0 happens when abs(Z)==0 hits the ground, for continuous functions.
Obviously evaluating real and image for the same instant. You are not checking real at t0 and imag at t1 t1~=t2, are you?
Think it this way, the only complex points where you can ignore the angle are those with real and imaginary parts really small, both small at the same time.
That is precisely what abs() measures.
So, if it's about finding out [X Y] that meet
real(Z)==0 && imag(Z)==0
no need to split real and imag, go straight to
abs(Z)==0
if you find this answer useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John BG

댓글 수: 4

Walter Roberson
Walter Roberson 2017년 3월 7일
Right. abs(a+1i*b) for real a and b is defined as sqrt(a^2 + b^2), which can only be 0 if both a and b are 0, so abs(a+1i*b) acts like an "and" test for both a and b being 0.
John BG
John BG 2017년 3월 7일
Precisely, Mr Roberson, no need to split real() imag(), aim at abs() and end problem.
Matthieu Michel
Matthieu Michel 2017년 3월 8일
Thank you for the quick answer! The problem that I see coming with abs() is that, as you both mentionned, it is indeed only null when real(Z)=0 and imag(Z)=0. But the matrix Z does not contain any 0 (or maybe a few with a lot of luck). It contains (amongst a lot of other numbers) numbers arbritrarily close to zero and this is why I used the intersection method: if a point is >0 and the next is <0, MatLab provides me with a zero inbetween.
I could, of course, use the same contour method on abs() with two contour lines (e.g. [1,0]), which would give me an approximation area where the zeros are, but it won't be as good as an extrapolation method and, more problematically, it might be misleading since it could show areas not withholding any zeros.
I am wondering if the best option is not to compute the intersection of the two surfaces real(Z) and imag(Z) with the plane 0. But I didn't find anywhere the possibility of computing the intersection of three surfaces...
John BG
John BG 2017년 3월 8일
편집: John Kelly 2017년 3월 9일
Matthieu
now you have started wondering on the right direction.
Unless you are writing a PhD dissertation about the Complex plane, when the module is null, both Real() and Imag() are null.
With the really close values to zero, would you could do is to use floor() or ceil() or round(), or a combination of them with the right conditional commands.
The point is that you may save time using abs + floor, and it's time you have to write code solving something else.
I wonder if you would be so kind to mark my answer as accepted by clicking on the ACCEPT ANSWER button that only you see.
thanks in advance

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2017년 3월 7일

편집:

2017년 3월 9일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by