Option 1:
using JuMP, Ipopt
α_0 = 1.0
Lmin = -1.0
Lnom = 0.0
Lmax = 1.0
a = 0.0019727939
b = 0.0078887
model = Model(Ipopt.Optimizer)
@variable(model, Lmin <= x[1:2] <= Lmax)
@constraint(model, sum(x) == 1)
@NLobjective(
model,
Min,
ifelse(
x[1] < Lnom,
a * (x[1]-Lnom)^2 + α_0,
b * (x[1]-Lnom)^2 + α_0,
),
)
optimize!(model)
Option 2:
using JuMP, Ipopt
Lmin = -1.0
Lmax = 1.0
function α(x...)
α_0 = 1.0
Lnom = 0.0
a = 0.0019727939
b = 0.0078887
if Lmin <= x[1] < Lnom
return a * (x[1]-Lnom)^2 + α_0
else
return (b * (x[1]-Lnom)^2 + α_0)
end
end
model = Model(Ipopt.Optimizer)
@variable(model, Lmin <= x[1:2] <= Lmax)
@constraint(model, sum(x) == 1)
register(model, :α, 2, α; autodiff = true)
@NLobjective(model, Min, α(x...))
optimize!(model)