Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read the gekko error code (e.g. Position : 5, v3 etc)

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])
like image 735
Junho Park Avatar asked Nov 21 '19 18:11

Junho Park


1 Answers

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.

like image 176
Daniel Hill Avatar answered Nov 03 '22 03:11

Daniel Hill