Finding the roots of a polynomial

669 views
Skip to first unread message

Bob

unread,
Mar 5, 2009, 2:24:21 PM3/5/09
to sage-support
I need to find the roots of this polynomial, where are coefficients
are in this matrix:

coef=matrix([[1],[-1],[-1],[0]])

thanks in advance, and apologies if this is posted somewhere else, I
have not been able to find it.

(NOTE: looking for the MathCAD equivalent of "polyroots")


Mike Hansen

unread,
Mar 5, 2009, 2:47:18 PM3/5/09
to sage-s...@googlegroups.com
Hello,

On Thu, Mar 5, 2009 at 11:24 AM, Bob <got...@gmail.com> wrote:
>
> I need to find the roots of this polynomial, where are coefficients
> are in this matrix:
>
> coef=matrix([[1],[-1],[-1],[0]])

First, you should construct a polynomial. A matrix of coefficients is
not the preferred way to work with polynomials in Sage.

sage: coef=matrix([[1],[-1],[-1],[0]])
sage: R.<x> = QQ[]; R
sage: f = R( list(coef.column(0)) ); f
-x^2 - x + 1

Above, I created the polynomial ring R (in the variable x), and then I
created the polynomial by passing in the 0th column of the matrix in
as a list.

Next, you use the .roots() method to get the roots. If you don't
specify an additional ring, it will default to the one that the
polynomial is defined over.

sage: f.roots()
[]
sage: f.roots(QQ)
[]

The above says that the polynomial has no rational roots. You
probably want floating point complex numbers (which is what polyroots
in MathCAD gives).

sage: CDF
Complex Double Field
sage: f.roots(CDF)
[(-1.61803398875, 1), (0.61803398875, 1)]

--Mike

Bob

unread,
Mar 5, 2009, 3:08:25 PM3/5/09
to sage-support
Mike, thanks, you da man!
Reply all
Reply to author
Forward
0 new messages