如何读取 gekko 错误代码(例如 Position : 5、v3 等) [英] How to read the gekko error code (e.g. Position : 5, v3 etc)

查看:25
本文介绍了如何读取 gekko 错误代码(例如 Position : 5、v3 等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在位置:5"中遇到语法错误.我无法找到错误的来源,因为不知道位置 5"指示的位置.如何通过读取错误代码来识别原始代码中的问题行?还有,v3 是什么意思?

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?

错误代码

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])

推荐答案

应该是 x1.dt()x2.dt() 而不是 x1.dtx2.dt.缺少括号会导致无法正确评估等式.

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.

这篇关于如何读取 gekko 错误代码(例如 Position : 5、v3 等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆