# Frobenius Norm objective with JuMP

**URL:** https://discourse.julialang.org/t/frobenius-norm-objective-with-jump/93338
**Category:** Optimization (Mathematical)
**Tags:** question, jump
**Created:** [January 21, 2023, 8:48pm UTC](https://discourse.julialang.org/t/frobenius-norm-objective-with-jump/93338 "2023-01-21T20:48:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![apateonas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/apateonas/32/38650_2.png) [@apateonas](https://discourse.julialang.org/u/apateonas)
#### Post date: [January 21, 2023, 8:48pm UTC](https://discourse.julialang.org/t/frobenius-norm-objective-with-jump/93338/1 "2023-01-21T20:48:35Z")

</div>

I am looking to use the frobenius norm of a matrix as an objective. Here is the setup:

```julia
nkrauss = 4

model = Model(Ipopt.Optimizer)

# Krauss operator variables
nKelems = nkrauss * dims^2
Kelems = [@variable(model, set = ComplexPlane()) for i in 1:nKelems]
Ks = reshape(Kelems, (dims, dims, nkrauss))

constraints = [@constraint(model, K' * K .== I) for K in eachslice(Ks, dims=3)]

approx = sum(Array([K * r * K' for K in eachslice(Ks, dims=3)]))

@NLobjective(model, Min, sum((approx - rprime) .^ 2))

```

I see the following error:

> ERROR: Unrecognized function “.^” used in nonlinear expression.

Where am I going wrong? Is there a better way to implement a Frobenius norm objective?

Thank you!

---

<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, 2023, 12:27am UTC](https://discourse.julialang.org/t/frobenius-norm-objective-with-jump/93338/2 "2023-01-22T00:27:23Z")

</div>

The `ComplexPlane` support in JuMP is very new, and it doesn’t work well with the nonlinear objective functions, and the nonlinear interface doesn’t support vector-valued expressions. (We’re working one improving this though.) In the near term, you’ll have to write out the scalar version of the norm:

```julia
model = Model()
A = [@variable(model, set = ComplexPlane()) for i in 1:2, j in 1:2]
# @NLobjective(model, Min, sqrt(sum(abs2(A[i, j]) for i in 1:2, j in 1:2)))
# since sqrt is monotonic, equivalent to:
@NLobjective(model, Min, sum(abs2(A[i, j]) for i in 1:2, j in 1:2))

```

---

<div class="post-metadata">

### Author: ![apateonas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/apateonas/32/38650_2.png) [@apateonas](https://discourse.julialang.org/u/apateonas)
#### Post date: [January 22, 2023, 1:14am UTC](https://discourse.julialang.org/t/frobenius-norm-objective-with-jump/93338/3 "2023-01-22T01:14:47Z")

</div>

Makes sense, thanks for the reply!
