Oct-20-2020, 09:46 AM
(This post was last modified: Oct-20-2020, 09:46 AM by Shiladitya.)
(Oct-19-2020, 10:08 PM)scidam Wrote: You need to define ranges wherebrute
will search for an optimum, e.g.
grid = ((-1, 1, 0.1), (-1, 1, 0.1)) # Also, you can use slice objects for this: # grid = (slice(-1, 1, 0.1), slice(-1, 1, 0.1))Further, you need to define a function to be optimized:
def f(x, T): return (x[0] - T) ** 2 + (x[1] - T) ** 2And, finally, usebrute
to find the minimum:
from scipy.optimize import brute brute(f, grid, (1,))
Thanks a lot for your kind reply.
And I have a question-
brute(f, grid, (1,))What does "(1,)" stand for? Is it the value of parameter 'T'?
And when defined the function, you used x[0] and x[1]; why?
Mathematically the function is 'f(x,y,T)=(x - T)^2 + (y - T)^2.
Am I right?