Skip to main content
4-Participant
May 9, 2016
Solved

Reason for getting 2 different plots, when plotted using polyroots and square roots function

  • May 9, 2016
  • 2 replies
  • 2404 views

Dear all,

I computed the roots of the quadratic equation by using two different methods,

1. square root function

2. Polyroots function

I found the values of the 2 functions are same.

But, when I try to plot the values of Imaginary part , I am getting different

plots for square root and polyroot function.

1. What is the reason behind that ?

2. How to get the similar result, which I got for square root function by using polyroot function?

I explained clearly in the attached code,

Thanks.

Best answer by StuartBruff

I think the mixing up of signs is due to the choice of solver for polyroots.  The default is an iterative LaGuerre method.  However, there is a companion matrix solver  (right-click on polyroots) for polyroots as well, and this seems to pick only one root.

collab - 16 05 09 polyroots 01.jpg

Stuart

2 replies

19-Tanzanite
May 9, 2016

The square root approach calculates all the positive roots separately from the negative roots.  The polyroots approach mixes them up, so the plot switches from positive to negative a lot, filling in gaps.   You could overcome this by choosing to plot points instead of lines, or adopt the more involved approach shown in the attached.

Alan

23-Emerald V
May 9, 2016

I think the mixing up of signs is due to the choice of solver for polyroots.  The default is an iterative LaGuerre method.  However, there is a companion matrix solver  (right-click on polyroots) for polyroots as well, and this seems to pick only one root.

collab - 16 05 09 polyroots 01.jpg

Stuart

vveeran4-ParticipantAuthor
4-Participant
May 9, 2016

Dear Stuart,

Thank you for your comments.

Your method seems to be much easier.

25-Diamond I
May 9, 2016

As was already noted the reason is the "arbitrary" way the solutions are arranged by polyroot:

Its the effect I already mentioned in your former thread with the third root.

I was not aware of the possibility to change the algorithm used as was pointed out by Stuart and that changing it would cure the problem in that elegant way.

My  suggestion would have been a user written Sort routine like the following (its a quick hack and won't work for multiple real solutions):

Werner

vveeran4-ParticipantAuthor
4-Participant
May 9, 2016

Dear Werner,

Thank you for your comments.