from matplotlib.pyplot import plot, show def f(x): if -1<=x<=4: return 4*x**2-x**3 def graph_f(n=100): a, b = -1, 4 h = (b-a)/n lx = [a+k*h for k in range(n+1)] ly = [f(x) for x in lx] plot(lx, ly) show() def parcours(p): x = -1 while x<=4: print(x, f(x)) x = x+p parcours(1) def maximum(p): x = -1 x0 = -1 while x<=4: if f(x)>f(x0): x0 = x x = x+p return (x0, f(x0)) print("Recherche du maximum, avec un pas de 1 :",maximum(1)) print("Recherche du maximum, avec un pas de 0.1 :",maximum(0.1)")