Closed frankligy closed 3 years ago
For the first function, you can use either the m.if2()
or m.if3()
(preferred) functions in Gekko to introduce the switching terms.
# here the k_repair is a python variable (constant value), X_var is a GEKKO variable
m.Equation(X_var.dt()==-k_repair*m.if3(X_var,0,1))
This implements binary switching conditions that are solvable with gradient based optimizers. You will also need to switch to m.options.IMODE=6
to solve the model as an optimization problem.
For the second function, please use the gekko m.sqrt()
function instead of the math.sqrt()
function. This is needed for the automatic differentiation in Gekko to efficiently solve the model.
Hi,
Thanks for this awesome library!
As an end-user that knows very little about the implementation and mathematical detail, I encountered an issue that I was hoping to get some bits of help with.
When defining
equation
, sometimes I need to involve customized defined functions that include operators likemath.sqrt
or piecewise function, like in the following example:I will get this error:
Another example:
I got this error:
As I said, I am not familiar with the math behind, but by looking at these errors, it seems like the culprit is the
math.sqrt
and<,>,=
operators that are not allowed in GEKKO, I am trying to understand is that true? If so, any workaround here because the ODE I am trying to simulate just has all these operators in the equation.Thanks a lot, Frank