scientific-programming-exer.../ex_47.py

16 lines
273 B
Python
Raw Normal View History

2019-01-23 14:27:28 +00:00
import numpy as np
from scipy.optimize import minimize
2019-01-23 15:47:12 +00:00
import matplotlib.pyplot as plt
2019-01-23 14:27:28 +00:00
f = lambda x: x*np.sin(7*x)*np.exp(-(x - 2)**2)
2019-01-23 15:47:12 +00:00
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()