# How to code the following optimization problem

**URL:** https://discourse.julialang.org/t/how-to-code-the-following-optimization-problem/69098
**Category:** Optimization (Mathematical)
**Tags:** convex-optimization
**Created:** [October 2, 2021, 6:39am UTC](https://discourse.julialang.org/t/how-to-code-the-following-optimization-problem/69098 "2021-10-02T06:39:57Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Jaidy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaidy/32/20310_2.png) [@Jaidy](https://discourse.julialang.org/u/Jaidy)
#### Post date: [October 2, 2021, 6:39am UTC](https://discourse.julialang.org/t/how-to-code-the-following-optimization-problem/69098/1 "2021-10-02T06:39:57Z")

</div>

Hi everyone,  
I have the following optimization problem to solve:  
minimize c^T_x, subject to ||c^T_x||\_1 \<= C

Can someone tell me how to write this in say NLopt, or any other library?

---

<div class="post-metadata">

### Author: ![zdenek\_hurak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdenek_hurak/32/53118_2.png) [@zdenek\_hurak](https://discourse.julialang.org/u/zdenek_hurak)
#### Post date: [October 2, 2021, 2:03pm UTC](https://discourse.julialang.org/t/how-to-code-the-following-optimization-problem/69098/2 "2021-10-02T14:03:25Z")

</div>

The very problem statement is rather confusing. At least for me. I assume that `x` and `c` are vectors (1d arrays of numbers). Then `c^Tx` is a scalar, but what does `||c^Tx||_1` mean? Why wouldn’t the constraint be written just as `|c^Tx|<=C`?

If my understanding of the problem statement is correct, that is,

```nohighlight
minimize c'x
subject to |c'x|<=C

```

the solution is pretty straightforward, isn’t it? Minimization of a linear function(al) with a lower (and upper) bound on its value. For a nonzero `c`, the minimum value of the functional is `-C`. A minimizer `x` can be found by solving

`c'x = -C`.

---

<div class="post-metadata">

### Author: ![Jaidy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaidy/32/20310_2.png) [@Jaidy](https://discourse.julialang.org/u/Jaidy)
#### Post date: [October 2, 2021, 7:26pm UTC](https://discourse.julialang.org/t/how-to-code-the-following-optimization-problem/69098/3 "2021-10-02T19:26:03Z")

</div>

sorry, I wrote it wrong! The correct problem is  
minimize 1’Ax,  
subject to ||Ax||\_1 \<=C

here A is a matrix, 1 is a vector of all ones

---

<div class="post-metadata">

### Author: ![zdenek\_hurak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zdenek_hurak/32/53118_2.png) [@zdenek\_hurak](https://discourse.julialang.org/u/zdenek_hurak)
#### Post date: [October 2, 2021, 10:04pm UTC](https://discourse.julialang.org/t/how-to-code-the-following-optimization-problem/69098/4 "2021-10-02T22:04:40Z")

</div>

```julia
using Convex, Clp

m,n = 2,3
A = rand(m,n)
γ = 3.0

x = Variable(n)
problem = minimize(sum(A*x), norm(A*x,1)<=γ)

solve!(problem, Clp.Optimizer)

problem.optval
x.value

```

---

<div class="post-metadata">

### Author: ![Jaidy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jaidy/32/20310_2.png) [@Jaidy](https://discourse.julialang.org/u/Jaidy)
#### Post date: [October 2, 2021, 10:57pm UTC](https://discourse.julialang.org/t/how-to-code-the-following-optimization-problem/69098/5 "2021-10-02T22:57:26Z")

</div>

thank you so much
