Problem in expressing the nonlinear objective

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:

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

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

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

so something like:

@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].

1 Like

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

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

https://jump.dev/JuMP.jl/stable/manual/nlp/#Syntax-notes

1 Like