# Constrained optimization with changing constraints based on value of target function

**URL:** <https://community.wolfram.com/t/constrained-optimization-with-changing-constraints-based-on-value-of-target-function/26327>\
**Category:** Questions\
**Tags:** optimization, numerical-computation\
**Created:** [January 13, 2026, 8:21pm UTC](https://community.wolfram.com/t/constrained-optimization-with-changing-constraints-based-on-value-of-target-function/26327 "2026-01-13T20:21:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![clejaniuval](https://avatars.discourse-cdn.com/v4/letter/c/dbc845/32.png) [@clejaniuval](https://community.wolfram.com/u/clejaniuval)\
**Post date:** [January 13, 2026, 8:21pm UTC](https://community.wolfram.com/t/constrained-optimization-with-changing-constraints-based-on-value-of-target-function/26327/1 "2026-01-13T20:21:40Z")

</div>

Is this possible, that some constraints have parameters that depend on the target function? Or do the constraints need to be statable in an unchanging way?

---

<div class="post-metadata">

**Author:** ![mroge02](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mroge02/32/28775_2.png) [@mroge02](https://community.wolfram.com/u/mroge02)\
**Post date:** [January 13, 2026, 9:02pm UTC](https://community.wolfram.com/t/constrained-optimization-with-changing-constraints-based-on-value-of-target-function/26327/2 "2026-01-13T21:02:06Z")

</div>

Do you mean something like this?:

```
NMinimize[{f, x^2 + y^2 + f^2 <= 4} /. f -> Cos[x] + Cos[y], {x, y}]
(* {0.356557, {x -> 1.39121, y -> -1.39191}} *)

```

---

<div class="post-metadata">

**Author:** ![clejaniuval](https://avatars.discourse-cdn.com/v4/letter/c/dbc845/32.png) [@clejaniuval](https://community.wolfram.com/u/clejaniuval)\
**Post date:** [January 15, 2026, 5:04pm UTC](https://community.wolfram.com/t/constrained-optimization-with-changing-constraints-based-on-value-of-target-function/26327/3 "2026-01-15T17:04:57Z")

</div>

Almost, but not quite. The constraints need to be defined outside NMinimize, as they are a bit complicated. See new file. It works now! Thanks.

[Open in Wolfram Cloud ↗](https://www.wolframcloud.com/obj/b648faf5-4f1b-4240-af97-c9734a53660e)

---

<div class="post-metadata">

**Author:** ![clejaniuval](https://avatars.discourse-cdn.com/v4/letter/c/dbc845/32.png) [@clejaniuval](https://community.wolfram.com/u/clejaniuval)\
**Post date:** [January 15, 2026, 5:06pm UTC](https://community.wolfram.com/t/constrained-optimization-with-changing-constraints-based-on-value-of-target-function/26327/4 "2026-01-15T17:06:34Z")

</div>

Wait, I need to add stuff that was in the original file, that I simplified… Hang on. It works now.
