cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

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

vveeran
4-Participant

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

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.

ACCEPTED SOLUTION

Accepted Solutions
StuartBruff
23-Emerald III
(To:AlanStevens)

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

View solution in original post

6 REPLIES 6

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

StuartBruff
23-Emerald III
(To:AlanStevens)

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

vveeran
4-Participant
(To:StuartBruff)

Dear Stuart,

Thank you for your comments.

Your method seems to be much easier.

vveeran
4-Participant
(To:AlanStevens)

Dear Alen,

Thank you for your comments.

I understand clearly from your plot.

Could you please suggest me some any other easier method

to compute polyroots which does not involves any for loop.

Werner_E
25-Diamond I
(To:vveeran)

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

vveeran
4-Participant
(To:Werner_E)

Dear Werner,

Thank you for your comments.

Announcements

Top Tags