I got a syntax error in 'Position: 5'. I can't find the source of the error as not knowing where 'the Position 5' indicates. How can I recognize the problematic line in the original code by reading the error code? And, what does the v3 mean?
Error code
Exception: @error: Model Expression
*** Error in syntax of function string: Invalid element: <boundmethodgkvariable
.dtof1>
Position: 5
v3-(<boundmethodgkvariable.dtof1>)
?
import numpy as np
from gekko import GEKKO
m = GEKKO()
nt = 101
m.time = np.linspace(0,1,nt)
# Variables
x1 = m.Var(value=1)
x2 = m.Var(value=0)
u = m.Var(value=-0.75)
p = np.zeros(nt)
p[-1] = 1.0
final = m.Param(value=p)
# Equations
m.Equation(x1.dt==u)
m.Equation(x2.dt==x1**2 + u**2)
# Objective Function
m.Obj(x2*final)
m.options.IMODE = 6
m.solve()
print(x1[-1], x2[-1])
It should be x1.dt()
and x2.dt()
instead of x1.dt
and x2.dt
. The lack of parenthesis is causing the equation to not be evaluated correctly.
Once that is fixed, the model solves properly. Overall a confusing error, but a simple fix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With