In [1]:
using Optim
In [3]:
using Plots
plotlyjs()
ezcontour(x, y, f) = begin
    X = repmat(x', length(y), 1)
    Y = repmat(y, 1, length(x))
    # Evaluate each f(x, y)
    Z = map((x,y) -> log(f([x,y])), X, Y)
    plot(x, y, Z, st=:contour)
end
WARNING: Method definition ezcontour(Any, Any, Any) in module Main at In[2]:3 overwritten at In[3]:3.
Out[3]:
ezcontour (generic function with 1 method)
In [4]:
f = x -> (x[1].^2 + x[2] - 11).^2 + (x[1] + x[2].^2 - 7).^2
sol = optimize(f, [0.0;0.0], NelderMead())
xs = sol.minimizer
Out[4]:
2-element Array{Float64,1}:
 3.00001
 1.99999
In [5]:
ezcontour(-5:0.02:5, -5:0.02:5, z -> f(z)[1])
scatter!([xs[1]],[xs[2]],label=false)
Out[5]: