finished ex_47
This commit is contained in:
parent
6e725459fc
commit
f7693ee0a4
10
ex_47.py
10
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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user