How to compare two complex numbers?

I am trying to implement Muller's method for computing the complex root of a polynomial.
Here r1,r2 could be complex in nature.
How do i compare r1 and r2. r1 >= r2 doesnt seem to be working. I have read elsewhere that > operator compares only the real part of the complex number. Is this true?

댓글 수: 4

Matt J
Matt J 2019년 8월 18일
Yes, it is true. What would you like r1>=r2 to mean?
Sarath S
Sarath S 2019년 8월 18일
편집: Sarath S 2019년 8월 18일
i would like it to return 1 if r1 is geater than or equal to r2.
ex. if r1 = 4 + 3i and r2 = 3 + 5i, then return 0 because |r1| < |r2|.
I thought that > would compare the magnitudes if it deals with complex numbers.
But i do realise that comparing two complex numbers doesnt make much sense.
Bruno Luong
Bruno Luong 2019년 8월 18일
편집: Bruno Luong 2019년 8월 18일
Then use
abs(r1) < abs(r2)
You notice this is NOT the same than r1 < r2 even for real numbers.
If you apply the first definition with r1=-4 and r2=2 it returns FALSE, which is kind of not comfortable to believe.
In fact there is no order relation for complex numbers.
TMW decides to implement a order relation on complex field that is extended from real number ordering, but rarely pertinent for application.
Sarath S
Sarath S 2019년 8월 18일
Okay. Thank you. I'll just go with one of the roots instead of comparing them.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Mathematics에 대해 자세히 알아보기

질문:

2019년 8월 18일

편집:

2019년 8월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by