# Fixing some regions of a Variable array in convex.jl

**URL:** https://discourse.julialang.org/t/fixing-some-regions-of-a-variable-array-in-convex-jl/101246
**Category:** Optimization (Mathematical)
**Tags:** question, convex
**Created:** [July 6, 2023, 8:56am UTC](https://discourse.julialang.org/t/fixing-some-regions-of-a-variable-array-in-convex-jl/101246 "2023-07-06T08:56:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![UgeB](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ugeb/32/51295_2.png) [@UgeB](https://discourse.julialang.org/u/UgeB)
#### Post date: [July 6, 2023, 8:56am UTC](https://discourse.julialang.org/t/fixing-some-regions-of-a-variable-array-in-convex-jl/101246/1 "2023-07-06T08:56:09Z")

</div>

The fix! function in the Convex.jl packages allows to fix the value of a variable to a constant during the optimization.  
I was wondering how I can get the same result with a multi-dimensional variable for which I want to fix only certain regions of the variable.

To illustrate my question, imagine I have a (n, k) Variable array over which I am running an optimization procedure in several steps. After each step I want to fix some of the rows of this array so that they cannot change during the next optimization step. Ideally I could do something like:  
fix!(var[idx,:])  
… solving problem …  
free!(var[idx,:])  
But this doesn’t seem to work.  
Any idea on how to tackle this problem ?  
Thanks for your help.

---

<div class="post-metadata">

### Author: ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)
#### Post date: [July 6, 2023, 9:06am UTC](https://discourse.julialang.org/t/fixing-some-regions-of-a-variable-array-in-convex-jl/101246/2 "2023-07-06T09:06:27Z")

</div>

You could add a new variable representing this row of your matrix, e.g. `col = Variable(n)`, then add an equality constraint, `var[idx, :] == col`, and then `fix!` and `free!` the variable `col`. I’m not sure if it will be the most efficient but it should work.

---

<div class="post-metadata">

### Author: ![UgeB](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ugeb/32/51295_2.png) [@UgeB](https://discourse.julialang.org/u/UgeB)
#### Post date: [July 6, 2023, 9:11am UTC](https://discourse.julialang.org/t/fixing-some-regions-of-a-variable-array-in-convex-jl/101246/3 "2023-07-06T09:11:38Z")

</div>

Thanks, I’ll try that !  
Actually in my case I never need to free the row again so I can just add an equality constraint, it was a stupid question, sorry.
