Minimization of a function in 3D
Source code name: ""
Programming language: Python
Topic: Data fitting/minuit
DMelt Version 1.4. Last modified: 02/22/2017. License: Free
To run this script using the DataMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.

from java.lang import Math
from jhplot import *

class MyFunc(FNon):  # define a function a*(x-2)^2 + (y+1)^2 
     def value(self, x):
              return (x[0]-2)*(x[0]-2)*self.p[0]+(x[1]+1)*(x[1]+1)

c1 = HPlot3D()                   # plot data and the fit function
pl = MyFunc("2D function",2,1) # 2 variables, 1 parameter     
print pl.numberOfParameters()
print pl.dimension()
print pl.parameterNames().tolist()
print pl.parameters()
c1.draw( F2D(pl,-10,10,-10,10) ) # create plottable function and show it 

from hep.aida.ref.optimizer.jminuit import *
op.setFunction(pl)                                 # set function 
op.variableSettings("x0").setValue(10)  # set initial value
op.variableSettings("x1").setValue(-10) # set initial value
op.optimize()                                         # perform optimization 
res =op.result()
print "Minimization results=",res.parameters(), " status=",res.optimizationStatus()