Examples of how to solve a quadratic degree equation in python using numpy:
With python we can find the roots of a polynomial equation of degree 2 ($ ax ^ 2 + bx + c $) using the function numpy: roots.
Consider for example the following polynomial equation of degree 2 $ x ^ 2 + 3x-0 $ with the coefficients $ a = 1 $, $ b = 3 $ and $ c = -4 $, we then find:
>>> import numpy as np
>>> coeff = [1,3,-4]
this equation has 2 real roots: $ x = -4 $ and $ x = 1 $.
Another example with $x^2+3x=0$
>>> coeff = [1,3,3]
which admits only two complex roots: $x=-1.5+0.8660254j$ et $x=-1.5-0.8660254j$.
Another example with $x^2-6x+9$
>>> coeff = [1,-6,9]
array([ 3. +3.72529030e-08j, 3. -3.72529030e-08j])
which admits a real root here: $x=3$ (car $3.72529030e-08$ est proche de $0$)
|Solving Quadratic Equation||stackoverflow|
|Python programming - How to solve quadratic equations using python||youtube|
|Finding polynomial roots using Python — Possible Numpy Extension Bug||stackoverflow|
Hi, I am Ben.
I have developed this web site from scratch with Django to share with everyone my notes. If you have any ideas or suggestions to improve the site, let me know ! (you can contact me using the form in the welcome page). Thanks!