Difference between revisions of "Python opt.minimize"

From TORI
Jump to navigation Jump to search
(Created page with "{{to}} Python opt.minimize is routine at Python programming language that searches the minimum of a given function. Example of the code: <pre> import scipy.optimize a...")
 
Line 25: Line 25:
 
</pre>
 
</pre>
   
The sixth element of the returned array seems to contain the array, and the zeroth element of the array is extremum (123) that realizes the minimal value (zero) of the function func.
+
The sixth element of the returned array seems to contain the array, and the zeroth element of the array is extremum (123) that realizes the minimal value (zero) of function func.
 
{{op}}
 
{{op}}
 
==References==
 
==References==

Revision as of 14:14, 4 December 2024


Python opt.minimize is routine at Python programming language that searches the minimum of a given function.

Example of the code:

import scipy.optimize as opt
def func(x):
 return (x-123)**2
x0 = 0
res = opt.minimize(func, x0)
print(res)

Output generated:

   status: 0
  success: True
     njev: 4
     nfev: 12
 hess_inv: array([[ 0.5]])
      fun: 5.553105828993429e-17
        x: array([ 122.99999999])
  message: 'Optimization terminated successfully.'
      jac: array([ -2.67164069e-12])

The sixth element of the returned array seems to contain the array, and the zeroth element of the array is extremum (123) that realizes the minimal value (zero) of function func.


References

https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html minimize(fun, x0, args=(), method=None, jac=None, hess=None, hessp=None, bounds=None, constraints=(), tol=None, callback=None, options=None)[source] Minimization of scalar function of one or more variables. Parameters: funcallable The objective function to be minimized. fun(x, *args) -> float where x is a 1-D array with shape (n,) and args is a tuple of the fixed parameters needed to completely specify the function. ..

Keywords

«Python»