From f6b2ea8938fdf3b00708bbe1b565dfe2882437ec Mon Sep 17 00:00:00 2001 From: "a.ott" Date: Wed, 29 Jan 2020 11:00:04 +0100 Subject: [PATCH] write small example case for scipy.optimize.minimize --- introduction/test_minimize.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 introduction/test_minimize.py diff --git a/introduction/test_minimize.py b/introduction/test_minimize.py new file mode 100644 index 0000000..e2fc298 --- /dev/null +++ b/introduction/test_minimize.py @@ -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() \ No newline at end of file