derive.py

Created by guilhemrf

Created on September 08, 2024

682 Bytes


# from math import *
from math import *

def derivee(f, x, h=1e-5):
    """Calcul de la dérivée numérique de f en x avec un pas h"""
    return (f(x + h) - f(x - h)) / (2 * h)

# Demander à l'utilisateur de saisir la fonction
expression = input("Entrez votre fonction de x (ex: 'x**2 + 3*x + 1'): ")

# Transformer l'expression en une fonction utilisable
def f(x):
    return eval(expression)

# Demander à l'utilisateur de saisir un point x où calculer la dérivée
x_val = float(input("Entrez la valeur de x où vous voulez calculer la dérivée: "))

# Calculer et afficher la dérivée en x_val
print("La dérivée de f en", x_val, "est", derivee(f, x_val))

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.