Multiplicity of the roots of a polynom

14 views
Skip to first unread message

Christophe

unread,
Jun 26, 2009, 5:23:41 AM6/26/09
to sy...@googlegroups.com
Hello,
the following code only gives [1] but I would also have the
multilplicity of the root 1 (which is 3) :
===============
x = sympy.Symbol('x')
f = '(x-1)**3'
sympy.solve(f, x)
===============

Is there a way to know that ?

Christophe.

Mateusz Paprocki

unread,
Jun 26, 2009, 7:38:11 AM6/26/09
to sy...@googlegroups.com
Hi Christophe,

there is a dedicated tool for obtaining polynomial roots, e.g.:

n [1]: var('x')
Out[1]: x

In [2]: f = (x - 1)**3

In [3]: roots(f, x)
Out[3]: {1: 3}

The result is a dictionary { root: multiplicity }. To get similar
behaviour to solve(), set the 'multiple' flag:

In [4]: roots(f, x, multiple=True)
Out[4]: [1, 1, 1]

Note however that solve() and roots() have different semantics. See
docstrings for details.

> f = '(x-1)**3'

btw. You don't have to enter expressions as strings.

--
Mateusz

signature.asc

Christophe

unread,
Jun 26, 2009, 8:39:39 AM6/26/09
to sy...@googlegroups.com
Mateusz Paprocki a écrit :

> there is a dedicated tool for obtaining polynomial roots, e.g.:
> In [3]: roots(f, x)
> Out[3]: {1: 3}
>
Thanks, that is very good for my purpose.

>> f = '(x-1)**3'
>>
> btw. You don't have to enter expressions as strings.
Indeed, I do that because I'll use sympy in a Python program that will
work with string.

Thanks a lot.
Christophe.

Reply all
Reply to author
Forward
0 new messages