Refactor: Ajoute de la documentation et de nouvelle implémentation pour les méthodes de calcul d'intervalle
This commit is contained in:
26
tp8.py
Normal file
26
tp8.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
|
||||
def euler(f, n: int, delta_x: float, x_0: float, y_0: float) -> list[float]:
|
||||
results = []
|
||||
|
||||
x = x_0
|
||||
y = y_0
|
||||
for i in range(n):
|
||||
x = x + delta_x
|
||||
y = y + delta_x * f(x, y)
|
||||
results.append(y)
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def exercice1() -> None:
|
||||
f = lambda x, y: -2 * x * y + 1
|
||||
results = euler(f, n=20, x_0=0, y_0=1, delta_x=.2)
|
||||
plt.plot(results)
|
||||
plt.title('Euler')
|
||||
plt.show()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
exercice1()
|
||||
Reference in New Issue
Block a user