Optim.jl optimize 2 variable function with initial boundaries

I’m struggling to accomplish a basic task with Optim.
Let’s say I defined a function f(a,x,y) = a + x^2 + y^2. I want to minimize this function given initial boundaries: x0 = [-10, 10], y0 = [-10, 10] and a = 10, as constant.

What do you mean by “initial boundary”? Are you looking for the minimum value of f within those bounds?

Yes. I want the optimizer to find the minimum value of f for x, y within the bounds, as well as return the corresponding x, y values.

Have you tried this?

1 Like

You can also use ProximalAlgorithms, see this example.

Note that the linked documentation refers to the master branch (a new release will be coming soon, which will then be covered by the documentation).

For fast convergence to high accuracy you can replace the ffb algorithm from the example with something like


(here is the relevant documentation for the algorithm)

1 Like

Thank you, but the docs don’t specify exactly how to handle multiple variables.

You can use a vector of length 2 as variable: in your example, you’ll be optimizing f(x) = x[1]^2 + x[2]^2.

1 Like