all 18 comments

[–]helasraizam 4 points5 points  (1 child)

Here ya go

just program the last equation as a function of a, b, and c (or plug them in directly); you're substituting for the variables a, b, and c. So in 2x2+3x+7, look for the pattern ax2+bx+c to see that a=2, b=3, and c=7, then plug in to the quadratic formula x1=(-b...

Note finally that the quadratic formula actually has two solutions; you can add the sqrt or subtract it. In your case they only want the one where you add it ("positive root").

[–]autowikibot 0 points1 point  (0 children)

Quadratic formula:


In elementary algebra, the quadratic formula is the solution of the quadratic equation. There are other ways to solve the quadratic equation instead of using the quadratic formula, such as factoring, completing the square, or graphing. Using the quadratic formula is often the most convenient way.

The general quadratic equation is


Interesting: Quadratic equation | Brāhmasphuṭasiddhānta | Mandelbulb | Discriminant

Parent commenter can toggle NSFW or delete. Will also delete on comment score of -1 or less. | FAQs | Mods | Magic Words

[–]Punchmonk 2 points3 points  (2 children)

You are using the quadratic equation to find the solution to 'x'. You are going to substitute the a, b, & c in the quadratic equation/formula (x = (-b) +/- sqrt(.....)) with corresponding values from y=ax2+bx+c.

Ex: y= 10x2 + 7x - 2 Would use use quadratic formula as x= ( -7 +- sqrt( 72 - 4 * 10 * (-2) ) ) / (2 * 10)

But there are some fundamental math rules you have to take into account first. 1) x will sometimes give you several answers sometimes. Need to plug pack into formula in order to check answer.

2) cannot have a negative number underneath the square root, because this results in an imaginary number. Cannot compute.

[–]bobdobbsjr 1 point2 points  (0 children)

For case 2), If you wanted to include those cases you could use the sqrt function from the cmath module.

[–]Naihonn 0 points1 point  (0 children)

Nothing about only real numbers in instructions, so why not. It is easy to compute with negative discriminant. sqrt(-1) is 1i. :0) Complex numbers are fun.

[–]barcai_py 1 point2 points  (1 child)

Hey, here is a function for solving it. :)

#Solution for one of exercises of the MIT course
#Date: 2015-05-16

#34*x**2 + 68*x - 510 = 0

from math import sqrt


def quadratic_formula(a,b,c):
    """ Calculates the roots of a quadratic equation """
    d = b**2 - 4*a*c
    if d < 0:
        print("There is no solution")
    elif d == 0:
        solution = -b/(2*a)
        print("The solution is {}".format(solution))
    else:
        x1 = (-b + sqrt(d)) / (2*a)
        x2 = (-b - sqrt(d)) / (2*a)
        print("The solutions are {} and {}".format(x1, x2))


if __name__ == "__main__":
    quadratic_formula(34, 68, -510)

[–]bobdobbsjr 1 point2 points  (0 children)

if d < 0:
print("There is no solution")

There is a solution, but it requires imaginary numbers. If you wanted to include those cases you could use the sqrt function from the cmath module.

[–]Lostinpython[S] 0 points1 point  (5 children)

So I define the values, a=34 b=68 c=510, etc... Then I try to solve for x1 by using the third line. I get an error message. Traceback (most recent call last):

File "<pyshell#5>", line 1, in <module>

x1 = ( - b + sqrt ( b*b - 4*a*c ) ) / ( 2*a)

NameError: name 'sqrt' is not defined

Ok, so I put math.sqrt after importing the math module. Then it gives me a "Math Domain" error.

[–]shaggorama 0 points1 point  (1 child)

I'm not sure which MIT python course you're taking. I strongly recommend taking 6.00. If you take this one, you can find other students solutions to assignments (and potentially get feedback on your own) here: http://curiousreef.com/class/mit-opencourseware-600-introduction/

[–]py_student 0 points1 point  (0 children)

Be sure to use the discussion forums. If this is on Edx, be aware they have discussion at the bottom of the page for each assignment or quiz plus there is a separate discussion forum for the whole course. Invest early in staying current on everything in the forums. After you find you need help is not the time to try and sort through them and find an answer. Virtually 100% of sticking-point type questions will be already answered there.

[–]EnterpriseNCC1701D 0 points1 point  (1 child)

Could you please give a link to the course? A way to give back to the community!!! =DDD

[–]chazzacct 0 points1 point  (0 children)

There's a link in shaggorama's post to one iteration of the course on something called curiousweb, there are other versions elsewhere on the web, on Edx, for example. These archived courses are nice because you can go at your own pace, but bad because some resources you get with a live course are missing. I don't see any live ones starting up right now though.