Complex roots equality problem
显示 更早的评论
I want to find the real roots of a polynomial that are 0<=roots<=1, for example:
>> rts=roots([16 -32 116 0 -100])
rts =
0.9050 + 2.6262i
0.9050 - 2.6262i
1.0000 + 0.0000i
-0.8100 + 0.0000i
I should be able to find that rts(3) satisfies these requirements. However,
>> myrt=rts(logical(~imag(rts) & real(rts)>=0 & real(rts)<=1))
myrt =
Empty matrix: 0-by-1
This is because real(rts(3))<=1 yields false, which is a bug so far as I can tell since complex(1,0)<=1 yields true. If I open the variable rts and double click rts(3) (which shows that it really is stored just like complex(1,0)), I can then execute real(rts(3))<=1 and it produces the correct result. What gives?
How do I find that rts(3) is the correct answer when I write a script? I am using MATLAB R2015b.
采纳的回答
更多回答(1 个)
Walter Roberson
2016-11-21
1 个投票
You will find that real(rts(3))-1 is not 0.
When I test on my Mac, in R2015b, rts(3) is 1+2*eps but in R2016b, rts(3) is 1-2*eps
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!