eq.py

Created by teivaetienne

Created on January 07, 2025

2.46 KB


def menu():
    print("=== Résolution d'Équations Différentielles ===")
    print("1. Équation différentielle du 1er degré")
    print("2. Équation différentielle du 2nd degré")
    print("0. Quitter")
    choix = int(input("Choisissez une option : "))
    return choix

def solve_first_order():
    print("\n--- Équation différentielle du 1er degré ---")
    print("Forme : y'(x) + P(x)y(x) = Q(x)")
    
    P = float(input("Entrez le coefficient P(x) constant : "))
    Q = float(input("Entrez le coefficient Q(x) constant : "))
    
    print("\nÉtapes :")
    print("1. Calculer le facteur intégrant μ(x) = exp(∫P(x)dx)")
    print("   Ici, μ(x) = exp(" + str(P) + "*x)")
    print("2. Multiplier toute l'équation par μ(x).")
    print("3. Résoudre la dérivée totale résultante.")
    
    print("\nSolution générale :")
    print("y(x) = (1/" + str(P) + ")*(" + str(Q) + ")*exp(-" + str(P) + "*x) + C*exp(-" + str(P) + "*x)")

def solve_second_order():
    print("\n--- Équation différentielle du 2nd degré ---")
    print("Forme : ay''(x) + by'(x) + cy(x) = 0")
    
    a = float(input("Entrez le coefficient a : "))
    b = float(input("Entrez le coefficient b : "))
    c = float(input("Entrez le coefficient c : "))
    
    print("\nÉtapes :")
    print("1. Résoudre l'équation caractéristique : ar2 + br + c = 0")
    
    delta = b**2 - 4*a*c
    print("   Discriminant ∆ = " + str(delta))
    
    if delta > 0:
        r1 = (-b + delta**0.5) / (2*a)
        r2 = (-b - delta**0.5) / (2*a)
        print("   Racines réelles distinctes : r1 = " + str(r1) + ", r2 = " + str(r2))
        print("   Solution : y(x) = C1*exp(" + str(r1) + "*x) + C2*exp(" + str(r2) + "*x)")
    elif delta == 0:
        r = -b / (2*a)
        print("   Racines réelles doubles : r = " + str(r))
        print("   Solution : y(x) = (C1 + C2*x)*exp(" + str(r) + "*x)")
    else:
        real = -b / (2*a)
        imag = (abs(delta)**0.5) / (2*a)
        print("   Racines complexes : " + str(real) + " ± " + str(imag) + "i")
        print("   Solution : y(x) = exp(" + str(real) + "*x)*(C1*cos(" + str(imag) + "*x) + C2*sin(" + str(imag) + "*x))")

def main():
    while True:
        choix = menu()
        if choix == 1:
            solve_first_order()
        elif choix == 2:
            solve_second_order()
        elif choix == 0:
            print("Au revoir !")
            break
        else:
            print("Choix invalide, veuillez réessayer.")

# Lancer le programme
main()

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.