How To Define Maximum Of Intermediate And Another Value In Python Gekko, When Using Sequential Solver?
In a modeling framework for solving systems of differential equations with GEKKO that I am writing I want to calculate the maximum of a parameter (an external forcing) and an integ
Solution 1:
IMODE=6
gives a good solution for this problem. It is still a simulation but allows the additional degrees of freedom. IMODE=4
checks that the number of equations and variables are equal. Both the m.max2()
and m.max3()
use additional degrees of freedom to solve the problem as shown here.
from gekko import GEKKO
import numpy as np
import matplotlib.pyplot as plt
m = GEKKO()
m.time = np.arange(0,20)
y = m.Var(value=5)
forcing = m.Intermediate(m.Param(value=np.arange(-5,15)))
@np.vectorize
def value_above_zero(var):
return m.max2(var, 0)
forcing_above_0 = value_above_zero(forcing)
m.Equation(y.dt()==-forcing_above_0*y)
m.options.IMODE=6
m.solve(disp=False)
Post a Comment for "How To Define Maximum Of Intermediate And Another Value In Python Gekko, When Using Sequential Solver?"