# Optimization on unit sphere?

**URL:** <https://discourse.julialang.org/t/optimization-on-unit-sphere/130720>\
**Category:** Optimization (Mathematical)\
**Created:** [July 14, 2025, 4:29pm UTC](https://discourse.julialang.org/t/optimization-on-unit-sphere/130720 "2025-07-14T16:29:34Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 15, 2025, 3:04pm UTC](https://discourse.julialang.org/t/optimization-on-unit-sphere/130720/8 "2025-07-15T15:04:21Z")

</div>

> [@ChrisRackauckas](#):
>
> A different simple trick is also just to define: x\_n = 1 - \sum\_k^{n-1} x\_k^2

You forgot the square root on the right-hand side. But with this approach you have the problem of picking a sign, and of constraining \sum\_k^{n-1} x\_k^2 \le 1; see also [Interior-Point Newton tries points outside of the constraint set](https://discourse.julialang.org/t/interior-point-newton-tries-points-outside-of-the-constraint-set/127215)

> [@kellertuer](#):
>
> determine the direction Y you want to “step into” as a vector tangent at the point on the sphere you are at

The change of variables x = y / \Vert y \Vert\_2 does this automatically, since \nabla\_y f(y / \Vert y \Vert\_2) \perp y.

> [@ForceBru](#):
>
> But I know that f(x) is convex and thus “easy” to optimize + the optimum is unique, so I don’t want to lose convexity.

You have already lost convexity (unless f is constant) because the feasible set is non-convex.

However, if your f(x) has a unique local (= global) optimum on the unit sphere, then f(y / \Vert y \Vert\_2) has a unique ray of optima y = \alpha x (\alpha \> 0), i.e. a unique value of x = y / \Vert y \Vert\_2. Local optimization will find an arbitrary y on that line, but will give the same x.

PS. As an aside, I would try hard to get a gradient of your function, if possible, so that you can use a better algorithm than DE.

---

_[View the full topic](https://discourse.julialang.org/t/optimization-on-unit-sphere/130720)._
