# import the gekko optimization package
from gekko import GEKKO
# create gekko model
m = GEKKO(remote=False)
# Constants
E = m.Const( 200000 )
by = m.Const( 1 )
phi = m.Const( 3.1456/2 )
F = m.Const( 5 )
# initialize needed variables
b = m.Var(value = 0.8 )
l = m.Var(value = 0.5 )
L = m.Var(value = 4 )
I = m.Var()
K = m.Var()
theta = m.Var()
a = m.Var()
h = m.Var( )
S_max = m.Var()
# Define the equation,
m.Equation( theta == m.asin(by/(L+(l/2))) )
m.Equation( a == l/2 + (L + l/2)*m.cos(theta) )
m.Equation( K == ( F*(L + l/2)*m.sin(phi-theta))/ theta )
m.Equation( I == (K*l)/E )
m.Equation( h == ( (12*I)/b) )
m.Equation(S_max == F*a*(h/2)/I )
# Constrains
m. Equation(S_max <= 4000)
# Define objective function
m.Obj( h )
# Set mode to steady state optimization (solution is not changing in time)
m.options.IMODE = 3
m.solve()
# Print result
print('h: ' + str(h.value))
Gekko:我正在使用Gekko优化我的cad模型参数。我的变量是相互依赖的。当我解的时候,它给出了错误。如何解决 代码给出了一个错误
Exception Traceback (most recent call last) in 52 m.options.IMODE = 3 53 ---> 54 m.solve() 55 56 # Print result
c:\users\rahdar\appdata\local\programs\python\python37\lib\site-packages\gekko\gekko.py in solve(self, disp, debug, GUI, **kwargs) 2057
print("Error:", errs) 2058 if (debug >= 1) and record_error: -> 2059 raise Exception(apm_error) 2060 2061 else: #solve on APM serverException: @error: Solution Not Found
如果重新排列方程式以避免被零除,并将
theta==m.asin(by/(L+(l/2)))
更改为m.sin(theta)==by/(L+(l/2))
,则会成功求解关于best practices for model building还有其他建议
相关问题 更多 >
编程相关推荐