degre2.py

Created by mino-1289

Created on January 22, 2021

755 Bytes

Trace une courbe du second degré, à partir de coefficients a,b, et c que vous donnez.


from math import sqrt 
from matplotlib import pyplot as plt
from mathsup import disc

a = float(input("a = "))
b = float(input("b = "))
c = float(input("c = "))

x = -10, 10, 0.1

def f(x,a,b,c):
    return a*x**2+b*x+c

y = f(x,a,b,c)

plt.plot(x,y,"red")

plt.grid(True)

if a != 0 and disc(a,b,c) >= 0:
    delta = disc(a,b,c)
    if delta == 0:
        x0 = -b/2*a
        plt.text(x0, f(x0,a,b,c), "x0")
    else:
        x1 = (-b+sqrt(delta))/(2*a)
        x2 = (-b-sqrt(delta))/(2*a)
        plt.text(x1, f(x1,a,b,c), "x1 = " + str(x1))
        plt.text(x2, f(x2,a,b,c), "x2 = " + str(x2))


plt.title("Courbe Cf (en rouge) de la fonction f = " + str(a) + "x2+" + str(b) + "x+" + str(c))
plt.ylabel("f(x)")
plt.xlabel("x")

plt.show()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.