Matlab bug with root and conj

69 Views Asked by At

I think I found a Matlab bug (I am using R2023a currently). My question is, how can I circumvent it.

Consider the following code

syms z
r1 = vpa( root( z^5 + z^4 + z^3 + z^2 + z^1 + 1 == 0, z, 1 ) )          % 0.5 + 0.866025403784438646763723170753i
r2 = conj( vpa( root( z^5 + z^4 + z^3 + z^2 + z^1 + 1 == 0, z, 1 ) ) )  % 0.5 - 0.866025403784438646763723170753i

s1 = vpa( root( z^5 + z^4 + z^3 + z^2 + z^1 + 1 == 0, z, 1 ) )          % 0.5 + 0.866025403784438646763723170753i
s2 = vpa( conj( root( z^5 + z^4 + z^3 + z^2 + z^1 + 1 == 0, z, 1 ) ) )  % 0.5 + 0.866025403784438646763723170753i

where r1 and r2 are correctly conjugated to each other, but s1 and s2 are the same. Thus, matlab seems to ignore the conj call for a "root-object" (I do not know the correct terminology here.

  • How can I correctly conjugate a "root-object"?
  • Respectively (my actual question may be easier to solve): How can I identify in Matlab whether two values are conjugate to each other.
1

There are 1 best solutions below

0
James Tursa On

Since there is no published preferred "order" (that I can find, anyway) for which root is root(expression,1), the Symbolic Toolbox is free to give you any order it wants. And since the Symbolic Toolbox knows that roots come in complex conjugate pairs when the coefficients are real, in the case of conj(roots(expression,1)), apparently the toolbox implicitly just switched the background order on you to simplify the expression. This expression is apparently interpreted as "conjugate of one of the roots of the expression", not "conjugate of the first root of this expression given a preferred order". Is the fact that the "order" of the roots is arbitrary and can be changed in the background depending on calling sequence and toolbox simplifications a bug? Particularly given that there is no preferred "order" published in the doc? I leave that up to you. If you request all of them at once and then convert them maybe you can work with that in your code without ambiguity. E.g.,

>> syms z
>> ex = z^5 + z^4 + z^3 + z^2 + z^1 + 1 == 0;
>> s = root(ex)
s =
 root(z^5 + z^4 + z^3 + z^2 + z + 1, z, 1)
 root(z^5 + z^4 + z^3 + z^2 + z + 1, z, 2)
 root(z^5 + z^4 + z^3 + z^2 + z + 1, z, 3)
 root(z^5 + z^4 + z^3 + z^2 + z + 1, z, 4)
 root(z^5 + z^4 + z^3 + z^2 + z + 1, z, 5)
>> vpa(s)
ans =
 - 0.5 - 0.86602540378443864676372317075294i
   0.5 - 0.86602540378443864676372317075294i
   0.5 + 0.86602540378443864676372317075294i
 - 0.5 + 0.86602540378443864676372317075294i
                                        -1.0

It would have been nice if MATLAB had returned root(ex,4) for conj(root(ex,1)) for consistency though. Maybe I will post a Question on MATLAB Answers to get their thoughts on this. Even nicer still if they had returned the complex conjugate pairs next to each other.