Re: Factoring Polynomials

2008-12-19 Thread Scott David Daniels
Tim Rowe wrote: 2008/12/18 Scott David Daniels : def quadsolve(a, b, c): try: discriminant = sqrt(b**2 - 4 * a * c) The discriminant of a quadratic is more usually just the b**2 - 4 * a * c part, not the square root of it. Testing that for negative, zero or positive avoids the need

Re: Factoring Polynomials

2008-12-19 Thread Tim Rowe
2008/12/18 Scott David Daniels : > def quadsolve(a, b, c): >try: >discriminant = sqrt(b**2 - 4 * a * c) The discriminant of a quadratic is more usually just the b**2 - 4 * a * c part, not the square root of it. Testing that for negative, zero or positive avoids the need to use an exce

Re: Factoring Polynomials

2008-12-18 Thread Terry Reedy
Collin D wrote: UPDATE: ' #import from math import sqrt # collect data a = float(raw_input('Type a value: ')) b = float(raw_input('Type b value: ')) c = float(raw_input('Type c value: ')) # create solver def solver(a,b,c): if b**2 - 4*a*c < 0: return 'No real solution.' else:

Re: Factoring Polynomials

2008-12-18 Thread Scott David Daniels
James Mills wrote: No worries. Please take an hour or two to go through the Python Tutorial at http://docs.python.org/ I'll bet is been more than a couple of days since you (James) ran through the tutorial. It is absolutely worth going through, but _nobody_ should imagine they are slow if the

Re: Factoring Polynomials

2008-12-18 Thread James Mills
On Fri, Dec 19, 2008 at 12:48 PM, Collin D wrote: > UPDATE: > > #import > from math import sqrt > > # collect data > a = float(raw_input('Type a value: ')) > b = float(raw_input('Type b value: ')) > c = float(raw_input('Type c value: ')) > > # create solver > def solver(a,b,c): >disc = b**2 -

Re: Factoring Polynomials

2008-12-18 Thread Collin D
On Dec 18, 6:41 pm, "Russ P." wrote: > On Dec 18, 6:31 pm, Collin D wrote: > > > > > > > On Dec 18, 6:27 pm, Collin D wrote: > > > > On Dec 18, 6:23 pm, "Russ P." wrote: > > > > > On Dec 18, 6:17 pm, Collin D wrote: > > > > > > On Dec 18, 6:12 pm, Collin D wrote: > > > > > > > On Dec 18, 11:3

Re: Factoring Polynomials

2008-12-18 Thread Russ P.
On Dec 18, 6:41 pm, "Russ P." wrote: > On Dec 18, 6:31 pm, Collin D wrote: > > > > > On Dec 18, 6:27 pm, Collin D wrote: > > > > On Dec 18, 6:23 pm, "Russ P." wrote: > > > > > On Dec 18, 6:17 pm, Collin D wrote: > > > > > > On Dec 18, 6:12 pm, Collin D wrote: > > > > > > > On Dec 18, 11:37 am

Re: Factoring Polynomials

2008-12-18 Thread Russ P.
On Dec 18, 6:31 pm, Collin D wrote: > On Dec 18, 6:27 pm, Collin D wrote: > > > > > On Dec 18, 6:23 pm, "Russ P." wrote: > > > > On Dec 18, 6:17 pm, Collin D wrote: > > > > > On Dec 18, 6:12 pm, Collin D wrote: > > > > > > On Dec 18, 11:37 am, collin.da...@gmail.com wrote: > > > > > > > I am t

Re: Factoring Polynomials

2008-12-18 Thread Collin D
On Dec 18, 6:27 pm, Collin D wrote: > On Dec 18, 6:23 pm, "Russ P." wrote: > > > > > > > On Dec 18, 6:17 pm, Collin D wrote: > > > > On Dec 18, 6:12 pm, Collin D wrote: > > > > > On Dec 18, 11:37 am, collin.da...@gmail.com wrote: > > > > > > I am trying to write a simple application to factor p

Re: Factoring Polynomials

2008-12-18 Thread Collin D
On Dec 18, 6:23 pm, "Russ P." wrote: > On Dec 18, 6:17 pm, Collin D wrote: > > > > > > > On Dec 18, 6:12 pm, Collin D wrote: > > > > On Dec 18, 11:37 am, collin.da...@gmail.com wrote: > > > > > I am trying to write a simple application to factor polynomials. I > > > > wrote (simple) raw_input li

Re: Factoring Polynomials

2008-12-18 Thread Russ P.
On Dec 18, 6:17 pm, Collin D wrote: > On Dec 18, 6:12 pm, Collin D wrote: > > > > > On Dec 18, 11:37 am, collin.da...@gmail.com wrote: > > > > 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 u

Re: Factoring Polynomials

2008-12-18 Thread Collin D
On Dec 18, 6:12 pm, Collin D wrote: > On Dec 18, 11:37 am, collin.da...@gmail.com wrote: > > > 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 e

Re: Factoring Polynomials

2008-12-18 Thread Collin D
On Dec 18, 11:37 am, collin.da...@gmail.com wrote: > 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

Re: Factoring Polynomials

2008-12-18 Thread Steven D'Aprano
On Thu, 18 Dec 2008 17:42:28 -0800, Collin D wrote: > The corrected function is: > def quadratic_solution(a,b,c) > sol1 = -1*b + ((b**2 - 4*a*c)**.5)/2*a > sol1 = -1*b - ((b**2 - 4*a*c)**.5)/2*a > return (sol1, sol2) > > Squaring the -b would give you some strange solutions :D

Re: Factoring Polynomials

2008-12-18 Thread Steven D'Aprano
On Fri, 19 Dec 2008 01:10:28 +, Steven D'Aprano wrote: > Because this looks like homework... Homework or not, of course others have answered it completely, more or less error-free. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Factoring Polynomials

2008-12-18 Thread Collin D
On Dec 18, 5:10 pm, Steven D'Aprano wrote: > On Thu, 18 Dec 2008 11:37:35 -0800, collin.day.0 wrote: > > 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 q

Re: Factoring Polynomials

2008-12-18 Thread James Mills
On Fri, Dec 19, 2008 at 11:37 AM, Collin D wrote: > Ahh. Great.. that answers a lot of questions. > Originally I was using just a = raw_input('a: ') > And was getting errors because you cant perform mathmatical operations > on strings. >.< > Thanks again! No worries. Please take an hour or two to

Re: Factoring Polynomials

2008-12-18 Thread Collin D
On Dec 18, 5:30 pm, "James Mills" wrote: > UPDATE: > > jmi...@atomant:~/tmp$ cat polycalc.py > #!/usr/bin/env python > > from math import sqrt > > def f(a, b, c): >     if (b**2 - (4 * a * c)) < 0: >         return None, None # Can't solve >     x1 = -b - (sqrt(b**2 - (4 * a * c)) / (2 * a)) >    

Re: Factoring Polynomials

2008-12-18 Thread James Mills
UPDATE: jmi...@atomant:~/tmp$ cat polycalc.py #!/usr/bin/env python from math import sqrt def f(a, b, c): if (b**2 - (4 * a * c)) < 0: return None, None # Can't solve x1 = -b - (sqrt(b**2 - (4 * a * c)) / (2 * a)) x2 = -b + (sqrt(b**2 - (4 * a * c)) / (2 * a)) return x1,

Re: Factoring Polynomials

2008-12-18 Thread James Mills
Hi Collin, Here you go: jmi...@atomant:~/tmp$ cat polycalc.py #!/usr/bin/env python from math import sqrt def f(a, b, c): if (b**2 - (4 * a * c)) < 0: return None, None # Can't solve x = (-1 * b) + (((b**2 - (4 * a * c)) ** 0.5) / (2 * a)) return (-1 * x), x print "Polynomi

Re: Factoring Polynomials

2008-12-18 Thread Steven D'Aprano
On Thu, 18 Dec 2008 11:37:35 -0800, collin.day.0 wrote: > 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

Re: Factoring Polynomials

2008-12-18 Thread Benjamin Kaplan
On Thu, Dec 18, 2008 at 7:59 PM, Collin D wrote: > On Dec 18, 4:41 pm, "James Mills" > wrote: > > On Fri, Dec 19, 2008 at 10:11 AM, Gabriel Genellina > > > > wrote: > > > En Thu, 18 Dec 2008 17:37:35 -0200, escribió: > > > > >> I am trying to write a simple application to factor polynomials. I

Re: Factoring Polynomials

2008-12-18 Thread Collin D
On Dec 18, 4:41 pm, "James Mills" wrote: > On Fri, Dec 19, 2008 at 10:11 AM, Gabriel Genellina > > wrote: > > En Thu, 18 Dec 2008 17:37:35 -0200, 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 val

Re: Factoring Polynomials

2008-12-18 Thread James Mills
On Fri, Dec 19, 2008 at 10:11 AM, Gabriel Genellina wrote: > En Thu, 18 Dec 2008 17:37:35 -0200, 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

Re: Factoring Polynomials

2008-12-18 Thread Gabriel Genellina
En Thu, 18 Dec 2008 17:37:35 -0200, 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 into pyth

Re: Factoring Polynomials

2008-12-18 Thread Collin D
On Dec 18, 1:09 pm, Mark Dickinson wrote: > On Dec 18, 8:47 pm, Scott David Daniels wrote: > > >      else: # a single result (discriminant is zero) > >          return (-b / (2 * a),) > > Maybe make that (-b / (2. * a)) to avoid getting funny results > when a and b are integers.  (Or do a from _

Re: Factoring Polynomials

2008-12-18 Thread eric
On Dec 18, 9:40 pm, "J. Cliff Dyer" wrote: > On Thu, 2008-12-18 at 11:52 -0800, eric wrote: > > On Dec 18, 8:37 pm, collin.da...@gmail.com wrote: > > > 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 > >

Re: Factoring Polynomials

2008-12-18 Thread Mark Dickinson
On Dec 18, 8:47 pm, Scott David Daniels wrote: >      else: # a single result (discriminant is zero) >          return (-b / (2 * a),) Maybe make that (-b / (2. * a)) to avoid getting funny results when a and b are integers. (Or do a from __future__ import division, or use Python 3.0, or )

Re: Factoring Polynomials

2008-12-18 Thread Scott David Daniels
eric wrote: On Dec 18, 8:37 pm, collin.da...@gmail.com wrote: ... I dont know how to implement the quadratic equation ... with numpy: from numpy import * s=[1,-1] x = -b+s*sqrt( b**2-4*a*c )/(2*a) Numpy is pretty heavyweight for this. For built in modules you have a few choices: For real

Re: Factoring Polynomials

2008-12-18 Thread J. Cliff Dyer
On Thu, 2008-12-18 at 11:52 -0800, eric wrote: > On Dec 18, 8:37 pm, collin.da...@gmail.com wrote: > > 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 qua

Re: Factoring Polynomials

2008-12-18 Thread Collin D
On Dec 18, 11:52 am, eric wrote: > On Dec 18, 8:37 pm, collin.da...@gmail.com wrote: > > > 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 equat

Re: Factoring Polynomials

2008-12-18 Thread eric
On Dec 18, 8:37 pm, collin.da...@gmail.com wrote: > 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 >

Factoring Polynomials

2008-12-18 Thread collin . day . 0
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 into python. Any ideas? -- http://mail.python.org/mailman/l