from gekko import GEKKO m = GEKKO() x,y = m.Array(m.Var,2) if x<=0: y = -1.0 * x else: y = 2.0 * x m.Minimize(y) m.solve()