# Problem in expressing the nonlinear objective

**URL:** <https://discourse.julialang.org/t/problem-in-expressing-the-nonlinear-objective/71127>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [November 8, 2021, 6:40am UTC](https://discourse.julialang.org/t/problem-in-expressing-the-nonlinear-objective/71127 "2021-11-08T06:40:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![FH96](https://avatars.discourse-cdn.com/v4/letter/f/4da419/32.png) [@FH96](https://discourse.julialang.org/u/FH96)\
**Post date:** [November 8, 2021, 6:40am UTC](https://discourse.julialang.org/t/problem-in-expressing-the-nonlinear-objective/71127/1 "2021-11-08T06:40:57Z")

</div>

Hi, I’m trying to express the NLobjective of a problem which is something like this : sum((A\*v\_j -v\_exp)^2) (A is a matrix)

I tried different forms and I got error in each case

`#@NLobjective(model,Min,sum((dot(module_flux[j,:],v[indx_of_P2])-measured_flux_of_modules[j,3])^2 for j in 1:size(measured_flux_of_modules,1)))`

`@NLobjective(model,Min,sum((module_flux[1,:]'*v[indx_of_P2]-measured_flux_of_modules[2,3])^2 for j in 1:size(measured_flux_of_modules,1 )))`

this is the error for each of the above code:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/6/a/6a06a4369caf220b1d53e2f8fd89092550138a75.png)

and for this one :  
`@NLobjective(model,Min,sum((module_flux*v[indx_of_P2]-measured_flux_of_modules[:,3]).^2 ))`

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/2/c2ef7d424fdeea90d83bbef9b64226973257d335.png)

I think I’m doing what the last error says in the other two versions of code, but as you see that error come up

---

<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:** [November 8, 2021, 6:57am UTC](https://discourse.julialang.org/t/problem-in-expressing-the-nonlinear-objective/71127/2 "2021-11-08T06:57:33Z")

</div>

You need to write all nonlinear expressions out as scalar expressions.

so something like:

```julia
@NLobjective(
    model,
    Min,
    sum(
        (
            sum(module_flux[1, i] * v[indx_of_P2[i]] for i in 1:size(module_flux, 2)) -
            measured_flux_of_modules[2, 3]
        )^2 for j in 1:size(measured_flux_of_modules, 1),
    ),
)

```

You can’t use linear algebra operations like `module_flux[1,:]'*v[indx_of_P2]`.

---

<div class="post-metadata">

**Author:** ![FH96](https://avatars.discourse-cdn.com/v4/letter/f/4da419/32.png) [@FH96](https://discourse.julialang.org/u/FH96)\
**Post date:** [November 8, 2021, 11:31am UTC](https://discourse.julialang.org/t/problem-in-expressing-the-nonlinear-objective/71127/3 "2021-11-08T11:31:00Z")

</div>

Thanks @odow, it worked  
Could you please explain why linear algebra operations can’t be used here ?

---

<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:** [November 8, 2021, 5:50pm UTC](https://discourse.julialang.org/t/problem-in-expressing-the-nonlinear-objective/71127/4 "2021-11-08T17:50:48Z")

</div>

Nonliner has limited syntax support. We hope to fix it in a future release.

[https://jump.dev/JuMP.jl/stable/manual/nlp/#Syntax-notes](https://jump.dev/JuMP.jl/stable/manual/nlp/#Syntax-notes)
