From f7693ee0a42b3af2ade38692211184bb9ec25ca6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kn=C3=BCttel?= Date: Wed, 23 Jan 2019 16:47:12 +0100 Subject: [PATCH] finished ex_47 --- ex_47.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ex_47.py b/ex_47.py index b4abd9b..f752279 100644 --- a/ex_47.py +++ b/ex_47.py @@ -1,5 +1,6 @@ import numpy as np from scipy.optimize import minimize +import matplotlib.pyplot as plt f = lambda x: x*np.sin(7*x)*np.exp(-(x - 2)**2) @@ -7,3 +8,12 @@ x0 = f(np.arange(-20, 20, 0.1)).min() m = minimize(f, x0, method="CG") print(m) + + +g = lambda x0: minimize(f, x0, method="CG").x +x0s = np.arange(-3, 3, 0.001) +xs = [g(x0) for x0 in x0s] + +plt.plot(x0s, xs) +plt.show() +