# Syntactical Question about optimize

**URL:** <https://discourse.julialang.org/t/syntactical-question-about-optimize/14771>\
**Category:** Optimization (Mathematical)\
**Tags:** optim\
**Created:** [September 10, 2018, 3:45pm UTC](https://discourse.julialang.org/t/syntactical-question-about-optimize/14771 "2018-09-10T15:45:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![OvidiusCicero](https://avatars.discourse-cdn.com/v4/letter/o/73ab20/32.png) [@OvidiusCicero](https://discourse.julialang.org/u/OvidiusCicero)\
**Post date:** [September 10, 2018, 3:45pm UTC](https://discourse.julialang.org/t/syntactical-question-about-optimize/14771/1 "2018-09-10T15:45:10Z")

</div>

Hi, someone not knowing much about optimization here…

Why does this code searching for the minimum of the two-dimensional paraboloid

```
optimize(x->x[1]^2+x[2]^2,[1.0, 1.0])

```

work without given algorithm whilst this one-dimensional equivalent

```
optimize(x->x[1]^2,[1.0])

```

only works with specified algorithm

```
optimize(x->x[1]^2,[1.0], BFGS())

```

(message says that NelderMead does not work with one variable)

Further, this version without vectors

```
optimize(x->x^2,1.0)

```

does not work at all for syntactical reasons, seemingly:

```
ERROR: MethodError: no method matching optimize(::getfield(Main, Symbol("##13#14")), ::Float64)

```

but the bound version in (-1.0,1.0) works fine (and is much more precise)

```
optimize(x->x^2,-1.0,1.0)

```

I stumbled across this because I want to optimize a one-dimensional function from a given starting point, not an interval

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [September 10, 2018, 9:03pm UTC](https://discourse.julialang.org/t/syntactical-question-about-optimize/14771/2 "2018-09-10T21:03:27Z")

</div>

Check out the docs for valid syntax [Optim.jl](http://julianlsolvers.github.io/Optim.jl/stable/#user/minimization/). The question about NelderMead is arguably a user experience bug. NelderMead is the default solver for vector inputs when only the objective function is given but it needs at least 2 variables, which probably means that there should be another fallback for the one variable vector case. You can open an issue about this on Github to get some more attention from the package authors.

---

<div class="post-metadata">

**Author:** ![OvidiusCicero](https://avatars.discourse-cdn.com/v4/letter/o/73ab20/32.png) [@OvidiusCicero](https://discourse.julialang.org/u/OvidiusCicero)\
**Post date:** [September 11, 2018, 8:08am UTC](https://discourse.julialang.org/t/syntactical-question-about-optimize/14771/3 "2018-09-11T08:08:36Z")

</div>

Edit: I misunderstood

```
optimize(x->x^2,1.0)

```

So this syntax is just unsupported?

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [September 11, 2018, 1:55pm UTC](https://discourse.julialang.org/t/syntactical-question-about-optimize/14771/4 "2018-09-11T13:55:23Z")

</div>

No it is not supported AFAIK, but maybe it should be. You can open an issue.
