TypeError: 'GKVariable' object is not callable

Viewed 574

I get an error when running the following code:

from gekko import GEKKO
m = GEKKO()
U1 = m.Param()
A1 = m.Param()
T2 = m.Var()
T1 = m.Var()
V1 = m.Var()
m.Equation(V1() == U1*A1*(T2-T1))
m.solve()
Traceback (most recent call last):
  File "C:\Users\johnh\Desktop\test.py", line 8, in <module>
    m.Equation(V1() == U1*A1*(T2-T1))
TypeError: 'GKVariable' object is not callable

How can I solve this error?

1 Answers

The error is with V1(). Either leave out the parenthesis to make it just V1 or else add the time derivative with V1.dt(). If this is an energy balance, you may want to make V1 a function of temperature such as m*cp*T1.dt() with the mass m and heat capacity cp.

Here is a dynamic simulation:

from gekko import GEKKO
m = GEKKO()
m.time = [0,1,2,3,4,5]
U1 = m.Param(1)
A1 = m.Param(1)
T2 = m.Param(1.1)
T1 = m.Param(1)
V1 = m.Var(0)
m.Equation(V1.dt() == U1*A1*(T2-T1))
m.options.IMODE = 4 
m.solve()
print(V1.value)

This produces the solution V1 = [0,0.1,0.2,0.3,0.4,0.5]

Related