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

**URL:** <https://discourse.julialang.org/t/using-optim-jl-optimization-like-fminsearch-in-matlab/6709>\
**Category:** Optimization (Mathematical)\
**Tags:** optim\
**Created:** [October 26, 2017, 8:02pm UTC](https://discourse.julialang.org/t/using-optim-jl-optimization-like-fminsearch-in-matlab/6709 "2017-10-26T20:02:21Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [October 29, 2017, 5:22am UTC](https://discourse.julialang.org/t/using-optim-jl-optimization-like-fminsearch-in-matlab/6709/16 "2017-10-29T05:22:06Z")

</div>

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:

```julia
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.

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

```

---

_[View the full topic](https://discourse.julialang.org/t/using-optim-jl-optimization-like-fminsearch-in-matlab/6709)._
