# Help optimizing a non-linear objective with JuMP

Here is a very stripped down toy example that is roughly equivalent to my real problem (without any constraints):

``````	using JuMP
using Ipopt

N = 54
r = rand(N)
R = rand()
model = Model(Ipopt.Optimizer)
@variable(model, s[1:N])
@NLobjective(
model,
Min,
sum(abs((r[i]/s[i]) - R) for i in 1:N)
)
JuMP.optimize!(model)
``````

`R` is a “target ratio” and I would like to minimize the sum of the absolute differences between each of 54 different ratios and the target ratio by modifying the denominators `s`. In my actual problem, r is a 54 x 4 matrix, there are 4 target ratios, and I have constraints that each value of `s` can take, as well as a constraint on the sum of `s` (and I’m trying to minimize the sum of the sums of the absolute differences). However, with the real problem and with this stripped down version, I get the following error: Also, if I call `objective_function(model)` it returns 0…Any ideas as to how I can formulate this problem?

Looks like a division by zero. Try setting a positive starting point for s.

1 Like

You should also try to add better bounds on `s`. Perhaps: `@variable(model, s[i=1:N] >= r[i])`

1 Like