Files
tp_ana_num/tp8.py

27 lines
503 B
Python

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()