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
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
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:
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
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 -
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
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
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
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
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
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
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
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
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
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
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
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
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))
>
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,
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
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
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
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
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
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
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 _
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
> >
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 )
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
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
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
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
>
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
33 matches
Mail list logo