Factoring Polynomials

Benjamin Kaplan benjamin.kaplan at case.edu
Fri Dec 19 02:05:54 CET 2008


On Thu, Dec 18, 2008 at 7:59 PM, Collin D <collin.day.0 at gmail.com> wrote:

> On Dec 18, 4:41 pm, "James Mills" <prolo... at shortcircuit.net.au>
> wrote:
> > On Fri, Dec 19, 2008 at 10:11 AM, Gabriel Genellina
> >
> > <gagsl-... at yahoo.com.ar> wrote:
> > > En Thu, 18 Dec 2008 17:37:35 -0200, <collin.da... at gmail.com> escribió:
> >
> > >> I am trying to write a simple application to factor polynomials. I
> > >> wrote (simple) raw_input lines to collect the a, b, and c values from
> > >> the user, but I dont know how to implement the quadratic equation
> >
> > >> x = (-b +or- (b^2 - 4ac)^1/2) / 2a
> >
> > Why is this so hard ? This is simple simple
> > expression. Reading through the Python
> > tutorial and reading up on how to define
> > functions is all you need! :)
> >
> > Here goes:
> >
> > >>> def f(a, b, c):
> >
> > ...     x = (-1 * b) + ((b**2 - (4 * a * c)) / (2 * a))
> > ...     return (-1 * x), x
> > ...
> >
> > >>> f(1, 2, 3)
> > (6, -6)
> >
> > cheers
> > James
>
> Hiya James!
>
> Just one small problem with your equation above...
> The quadratic formula is:
> x = -b +or- (b**2 - (4 * a * c))^1/2 / 2a
>
> You just forgot the square root which makes quadratic a bit more
> complicated.
> You would have to download and import sqrt() from numpy or **.5
>

why do you need sqrt from numpy? Is there a problem with math.sqrt or does
no one realize that it exists?



>
> Also.. I need to build in functionality so the user does not have to
> directly call the function like:
> f(a,b,c)
>

a = float(raw_input("a="))
b = float(raw_input("b="))
c = float(raw_input("c="))
result = f(a,b,c)

>
> Instead.. they should be able to just raw_input their values.
> Also.. as with some of the examples above its a good idea to analyze
> the discriminant to make sure we have a real solution.
> Of course.. thats all pretty simple to build in. Thanks a lot!
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081218/a240a0d4/attachment.html>


More information about the Python-list mailing list