I tried to use an old JuMP model that was working with JuMP 0.18. But the behaviour of @NLexpression changed with JuMP 0.19 /0.20 / 0.21.
Is it a bug or I need to modify how the expression is written?
Thank you in advance for your reply!
n = m = 10
if m < n
@warn(": number of function must be ≥ number of variables. Adjusting to m = n")
m = n
end
nls = Model()
x0 = collect(1:n)/(n+1)
@variable(nls, x[i=1:n], start = x0[i])
function Tsim(x, n)
if n == 0
return 1
elseif n == 1
return x
else
return 2*x*Tsim(x,n-1) - Tsim(x,n-2)
end
end
Ts = Vector{Function}(undef, n)
Tnames = Vector{Symbol}(undef, n)
for i = 1:n
Ts[i] = x -> Tsim(2*x-1, i)
Tnames[i] = gensym()
JuMP.register(nls, Tnames[i], 1, Ts[i], autodiff=true)
end
I = [i%2 == 0 ? -1/(i^2-1) : 0 for i = 1:n]
@NLexpression(nls, F[i=1:n], sum($(Tnames[i])(x[j]) for j = 1:n)/n - I[i])