GEKKO Inconsistent result with MODE 4 and 7

Viewed 35

Solving problem with 2 nodes.

Given Problem

    m = GEKKO()
    m.time = np.linspace(0, 5, 2)
    x = m.Var(1)
    m.Equation(x.dt() == 1)

If solve with MODE 7

    m.options.IMODE = 7
    m.options.SOLVER = 2
    m.solve(disp=False)

    x = [1.0, 1.0]

If solve with MODE 4

    m.options.IMODE = 4
    m.options.SOLVER = 2
    m.solve(disp=False)
    
    x = [1.0, 6.0]
1 Answers

It appears that there is a bug with how Gekko reports the solution when there is only 1 time step with IMODE=7. Switching to two time steps gives a consistent and correct solution for both IMODE=7 and IMODE=4.

from gekko import GEKKO
import numpy as np
m = GEKKO()
m.time = np.linspace(0, 5, 3)
x = m.Var(1)
m.Equation(x.dt() == 1)
m.options.IMODE = 7
m.options.SOLVER = 2
m.solve(disp=False)
print(x.value)

When IMODE=4 the solution is also [1.0, 3.5, 6.0].

Related