473,499 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pylab, matplotlib ... roots function question

Hello NG,

given this call to roots funtion from pylab

In [342]: roots([0,2,2])
Out[342]: array([-1.])

as far as I understand it [a0,a1,a2] stands for a0+a1*x+a2*x^2
in the above case it yields 2x^2+2x = 2x(1+x)
and the roots are 0 and -1
I am wondering why roots function gives me only the -1

second try

In [343]: roots([1,0,0])
Out[343]: array([], dtype=float64)

ok, as it should be

In [344]: roots([0,0,1])
Out[344]: array([], dtype=float64)

here again, 0 is the root of x^2

Do I miss something important?
Regards, Daniel
Jan 22 '07 #1
2 2019
Schüle Daniel wrote:
Hello NG,

given this call to roots funtion from pylab
It's actually from numpy and numpy questions are best asked (and best answered!)
on numpy-discussion.

http://www.scipy.org/Mailing_Lists
In [342]: roots([0,2,2])
Out[342]: array([-1.])

as far as I understand it [a0,a1,a2] stands for a0+a1*x+a2*x^2
in the above case it yields 2x^2+2x = 2x(1+x)
and the roots are 0 and -1
I am wondering why roots function gives me only the -1
No, it's the other way around.

In [1]: from numpy import *

In [2]: roots?
Type: function
Base Class: <type 'function'>
Namespace: Interactive
File:
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/numpy-1.0.2.dev3507-py2.5-macosx-10.4-i386.egg/numpy/lib/polynomial.py
Definition: roots(p)
Docstring:
Return the roots of the polynomial coefficients in p.

The values in the rank-1 array p are coefficients of a polynomial.
If the length of p is n+1 then the polynomial is
p[0] * x**n + p[1] * x**(n-1) + ... + p[n-1]*x + p[n]
So you were really solving 2*x + 2 = 0, the single root of which is -1.
second try

In [343]: roots([1,0,0])
Out[343]: array([], dtype=float64)

ok, as it should be
No, that's actually wrong. What version of numpy are you using? With a recent
SVN checkout of numpy, I get the correct answer:

In [3]: roots([1,0,0])
Out[3]: array([ 0., 0.])

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Jan 22 '07 #2
Hi,

[...]
No, that's actually wrong. What version of numpy are you using? With a recent
SVN checkout of numpy, I get the correct answer:

In [3]: roots([1,0,0])
Out[3]: array([ 0., 0.])
In [17]: import sys, numpy

In [18]: sys.version
Out[18]: '2.5 (r25:51908, Sep 23 2006, 01:23:14) \n[GCC 4.1.1]'

In [19]: numpy.version.version
Out[19]: '1.0rc1'
moon:/pool/PROG/python # uname -a
Linux moon 2.6.16.13-4-smp #1 SMP Wed May 3 04:53:23 UTC 2006 x86_64
x86_64 x86_64 GNU/Linux

I think I will get and compile newer version of source

BTW, I also look for good (more or less complete and/or interessting)
tutoruals on signal processing with python
something like low/high-pass filtering/ploting of wave files etc
I would appreciate pointers very much.

I am learning this at the moment, when it all starts to make sense to
me, I will write such a tutorial on my own later

Regards, Daniel
Jan 22 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2674
by: jean.rossier | last post by:
Hello All, I am facing a problem while importing pylab library(in a .py program file) via web browser however the same program works when I execute it from the command prompt. my...
3
4014
by: Dr. Colombes | last post by:
On my home laptop computer, I'm trying to install the appropriate modules so that Python version 2.3.3 and IDLE version 1.0.2 (with an "import matplotlib.matlab" statement) can produce nice...
2
7788
by: Charles Krug | last post by:
List: I'm trying to us pylab to see what I'm doing with some DSP algorithms, in case my posts about convolution and ffts weren't giving it away. I've been using pylab's plot function, but I'm...
2
1801
by: Gary Wessle | last post by:
Hi I use debian/testing linux Linux debian/testing 2.6.15-1-686 I found some duplicate files in my system, I don't if the are both needed, should I delete one of the groups below and which...
2
2701
by: timw.google | last post by:
Hi all. I installed matplotlib 0.87.3 under Python 2.4 on both Linux (FC3) and Windows XP Pro. On the linux install, I can import pylab, but when I try to do the same thing on the Windows...
0
1952
by: ehenlin | last post by:
Hi, How to make pylab work together with py2exe? Have anyone managed to build a stand alone exe with pylab package? I have made a small test script but that does not work. setup.py...
14
6716
by: amitsoni.1984 | last post by:
hi, I have some values(say from -a to a) stored in a vector and I want to plot a histogram for those values. How can I get it done in python. I have installed and imported the Matplotlib package...
1
2405
by: oyinbo55 | last post by:
I am trying to use the pylab plot command on my laptop running Ubuntu 6.06 (Dapper). Although the plot command works fine on my XP desktop at work, I cannot open the plot window on the laptop. I...
3
2796
by: Willem-Jan Vriend | last post by:
I want to use pylab (matplotlib) on a machine without X11. I'm trying to generate onthefly graphics for an apache2 web service, so they do not have to be displayed on this machine ! When i do...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7012
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6901
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4920
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3105
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3101
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.