I'm trying to solve non-linear equations in GEKKO using bounds and initial values. The following example illustrates two main problems I'm trying to solve for a larger system of non-linear equations.
from gekko import GEKKO
import numpy as np
m = GEKKO()
a = m.Const(value=1)
b = m.Const(value=1)
x = m.Var(value=3,lb=0)
y = m.Var(value=3,lb=0)
m.Equation(10**-x + y == a)
m.Equation(x - 10**y == b)
m.solve(disp=False)
print(x.value,y.value)
This gives a solution of:
[10.999999998] [0.99999999999]
Problem 1 - I want to solve x,y using an input range of a constants, and also not be concerned with rounding errors. For example, can I incorporate an np.linspace?
a = np.linspace(1,10,10)
Problem 2 - By the time a=4, the initial value of value=3 will not work. To get around this, I'd like to use the x,y solutions for to be the initial values for the next iteration. For example, for a=1 the solution is [10.999999998] [0.99999999999] which I'd like to be the initial values for the next iteration at a=2:
x = m.Var(value=10.999999998,lb=0)
y = m.Var(value=0.99999999999,lb=0)
and so on until it gets to a=10.
Use
m.Param()foraso thata.valuecan be adjusted with every loop. Thex.valueandy.valuecan also be adjusted to give an initial guess. Gekko automatically stores the prior solution as the new initial guess so it is not required to reinitializexandy.This gives solutions:
Another way to solve this is with
IMODE=2to solve all of the permutations inaat once. For this problem it takes an initialization withIMODE=3. This is potentially much faster so that one larger optimization problem is solved instead of a series of optimization problems.The result is the same: