Sure thing. I’m going to post the `@NLexpression`

version:

```
#u -> A 65x1 previously calculated float vector
#Yh_real and Yh_imag -> 65x65x15 previously calculated float arrays
Nt = 65;
fq = 100;
barramin = 27;
barramax = 30;
hsmin = 3;
hsmax = 15;
hmax = 15;
Xcf = zeros(Nt,1);
Cf = zeros(Nt,1);
for i = 1:Nt
if i >= barramin && i <= barramax
Xcf[i] = u[i]^2/Qmod;
Cf[i] = 1/(2*pi*60*Xcf[i]);
end
end
m = Model(solver=CouenneNLSolver())
@variable(m, a[i = barramin:barramax], Bin)
@variable(m, hsmin <= hs[i=barramin:barramax] <= hsmax, Int)
@variable(m, Vh_filtro_real[i = 1:Nt,h = 3:2:hmax])
@variable(m, Vh_filtro_imag[i = 1:Nt,h = 3:2:hmax])
@variable(m, DHTv3_filtro[i = 1:Nt] <= DHTv3_max)
@variable(m, DHTvI_filtro[i = 1:Nt] <= DHTvI_max)
Yh_filtro_real = Dict();
Yh_filtro_imag = Dict();
@objective(m, Min, sum(a[i] for i = barramin:barramax))
@NLexpression(m, y5_real[i = barramin:barramax, h = 3:2:hmax], (Xcf[i]/(fq*(2*hs[i]+1)))/((Xcf[i]/(fq*(2*hs[i]+1)))^2+(h*Xcf[i]/((2*hs[i]+1)^2)-Xcf[i]/h)^2))
@NLexpression(m, y5_imag[i = barramin:barramax, h = 3:2:hmax], (-h*Xcf[i]/((2*hs[i]+1)^2)+Xcf[i]/h)/((Xcf[i]/(fq*(2*hs[i]+1)))^2+(h*Xcf[i]/((2*hs[i]+1)^2)-Xcf[i]/h)^2))
for h = 3:2:hmax, L = 1:Nt, C = 1:Nt
if L == C && (L >= barramin && L <= barramax)
Yh_filtro_real[L, C, h] = @NLexpression(m, Yh_real[L,C,h]+a[L]*y5_real[L,h]);
Yh_filtro_imag[L, C, h] = @NLexpression(m, Yh_imag[L,C,h]+a[L]*y5_imag[L,h]);
else
Yh_filtro_real[L, C, h] = @NLexpression(m, Yh_real[L,C,h]);
Yh_filtro_imag[L, C, h] = @NLexpression(m, Yh_imag[L,C,h]);
end
end
for h = 3:2:hmax, L = 1:Nt
@NLconstraint(m, sum(Yh_filtro_real[L,C,h]*Vh_filtro_real[C,h]-Yh_filtro_imag[L,C,h]*Vh_filtro_imag[C,h] for C = 1:Nt) == Ih_real[L,h])
@NLconstraint(m, sum(Yh_filtro_imag[L,C,h]*Vh_filtro_real[C,h]+Yh_filtro_real[L,C,h]*Vh_filtro_imag[C,h] for C = 1:Nt) == Ih_imag[L,h])
end
@NLexpression(m, Vh_filtro[i = 1:Nt,h = 3:2:hmax], sqrt(1e-20+Vh_filtro_real[i,h]^2+Vh_filtro_imag[i,h]^2))
@NLconstraint(m, con5[i = 1:Nt], DHTv3_filtro[i] == sqrt(1e-20+sum(Vh_filtro[i,h]^2 for h = 3:2:hmax if rem(h,3) == 0))/u[i]*100)
@NLconstraint(m, con6[i = 1:Nt], DHTvI_filtro[i] == sqrt(1e-20+sum(Vh_filtro[i,h]^2 for h = 3:2:hmax if rem(h,3) != 0))/u[i]*100)
status = solve(m)
```