write small example case for scipy.optimize.minimize
This commit is contained in:
parent
0adb8e98b9
commit
f6b2ea8938
18
introduction/test_minimize.py
Normal file
18
introduction/test_minimize.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
from scipy.optimize import minimize
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
guess = np.zeros(3)
|
||||||
|
fmin = minimize(fun=cost1, x0=guess, args=(3, 20, -25), method="Nelder-Mead")
|
||||||
|
|
||||||
|
print(fmin)
|
||||||
|
|
||||||
|
|
||||||
|
def cost1(X, a=2, b=9, c=15):
|
||||||
|
return (X[0]-a)**2 + (X[1]-b)**2 + (X[2]-c)**2
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user