kop

an anonymous user · November 19, 2023
import numpy as np
import matplotlib.pyplot as plt

t0 = 0
tf = 10
n = 15
t = np.linspace(t0, tf, n)
E = 10
u0 = 0
Tau = 1

def f(u, t):
    return -u / Tau + E / Tau

def euler(f, x0, t):
    h = t[1] - t[0]
    n = len(t)
    u = np.zeros(n)
    u[0] = x0  # en remplace x par u 
    for i in range(n - 1):
        u[i + 1] = u[i] + h * f(u[i], t[i])  # ici aussi
    return u

result = euler(f, u0, t)
plt.plot(t, result)
plt.xlabel('Temp')
plt.ylabel('u(t)')
plt.title("approximation d'Euler, n=15")
plt.show()



# Equation
volt = E * (1 - np.exp(-t / Tau))

# graphe
plt.plot(t, volt, label='Volt (V)')
plt.xlabel('t')
plt.ylabel('Volt')
plt.title('U(t) theorique vs E.n=15')
plt.show()





Output

Comments

Please sign up or log in to contribute to the discussion.