I have a non-linear user-defined function, y = myfun(x), where the output y is a 1*2 array.
I am going to use the output y to construct constraints. I will have 2 constraint equations since y has 2 components and each components constructs one constraint equation. In my case, my constraints will be something like: y >= 1, y >=1.
When the output length n = 1, I did the following and worked fine.
using JuMP using Ipopt dim = 2 x0 = ones((1,dim)).*35 # This is where I am confused, I have to # return y in order to make it work. # And I don't know what to do if I want to return # both y and y function myfun(x...) y = zeros(eltype(x), 2) y = sin(x) + x^2 y = 1/x + x^2 return y end model = Model(Ipopt.Optimizer) @variable(model, 0.1 <= x[i = 1:dim] <= 35.0, start = x0[i]) register(model, :myfun, dim, myfun, autodiff = true) @NLconstraint(model, nlcon, myfun(x...) >= 1) @objective(model, Min, sum(x[i] for i in 1:dim)) optimize!(model) @show value.(x); @show objective_value(model);
Notice in myfun(x…), the output y has two components. But I have to return y in order to make this work for one constraint only. So what should I do if I want to keep both y and [y2]? Any help will be appreciated. Thank you in advance.