# Minimize Multiple norms using JuMP

**URL:** https://discourse.julialang.org/t/minimize-multiple-norms-using-jump/53763
**Category:** Optimization (Mathematical)
**Created:** [January 22, 2021, 6:57am UTC](https://discourse.julialang.org/t/minimize-multiple-norms-using-jump/53763 "2021-01-22T06:57:26Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![cheng\_chen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cheng_chen/32/20899_2.png) [@cheng\_chen](https://discourse.julialang.org/u/cheng_chen)
#### Post date: [January 22, 2021, 6:57am UTC](https://discourse.julialang.org/t/minimize-multiple-norms-using-jump/53763/1 "2021-01-22T06:57:26Z")

</div>

Hi,

I need to minimize an objective function that has multiple norms in it.  
Here is a minimal example:  
A is a variable of dimension d by n.  
x is a known constant matrix of dimension n by 1 and b\_t (dimension d by 1) is the data gathered with iterations. A0 is a known constant matrix of dimension d by n  
The objective function is: `Σ_{s=1}^{t}norm(A*x-b_t)^2+norm(A-A0)^2`. `Σ_{s=1}^{t}` means sum from s =1 to s = t.  
Suppose t is 3 and we know b\_1,b\_2,b\_3.  
We need the find the A that minimizes the objective function.  
How should we construct the model using JuMP?  
Here is the code i have:

```julia
using Ipopt
using JuMP
model = Model(Ipopt.Optimizer)
@variable(model, A[1:d, 1:n])
objective = 0.0
for s = 1:t
    objective = objective + norm(A*x-b[t])^2+norm(A-A0)^2
end
@NLobjective(model, Min, objective)
JuMP.optimize!(model)
```

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [January 22, 2021, 9:14pm UTC](https://discourse.julialang.org/t/minimize-multiple-norms-using-jump/53763/2 "2021-01-22T21:14:08Z")

</div>

You can add second order cone constraints as

```nohighlight
model = Model()
@variable(model, t)
@variable(model, x[1:4])
@constraint(model, [t; x] in SecondOrderCone())

```

If you want the squared norm, you can just write out

```nohighlight
d = 2
n = 3
T = 2
x = rand(n)
b = [rand(d) for t = 1:2]
A0 = rand(d, n)
model = Model()
@variable(model, A[1:d, 1:n])
@objective(
    model, 
    Min, 
    sum(sum((A * x .- b[t]).^2) for t = 1:T) + sum((A .- A0).^2),
)

```
