Using optim.jl ( optimization ) - like fminsearch in matlab

We would gladly help you if you provided a minimal example that, except for the optimization part, we can run: the function X2 you provide is incomplete; moreover it does not depend on x so any value of x is a minimizer:

function X2(x)
  aΩ11 = zeros( lenR )
  for i in lenR # here you probably want for i in 1:lenR 
    aΩ11[i] = afΩ11i # what is afΩ11i?
  end
  sum((aΩ11-aΩ11e).^2)
end

As for x not being defined, if you look at the code (corrected after @pkofod’s suggestion), the minimizer is called X2min, so yes, x is not defined.

X2min = Optim.minimizer(optimize(X2, [2.50,17.2,0.5,0.5], NelderMead(), Optim.Options(g_tol=1e-32)))
1 Like