简体   繁体   中英

Can the Python module gekko handle complex numbers?

I'm faced with an Hessenberg index-2 DAE, I'm trying to solve it using the python module gekko. After a few days of trial and error, I think I'm not too far from a code that works. But I've just realized that maybe gekko is not able to handle complex numbers?

Here is a minimal working example:

import numpy as np
from gekko import GEKKO

# Define the simulation and its parameters
g = GEKKO()
g.options.IMODE = 7
g.options.NODES = 1

# define the time array
n_steps = 100
Time = np.linspace(0, 2 * np.pi, n_steps)
g.time = Time

# Initialise the variables
x = g.Var(0.0)

# Write the model's equations
g.Equation(x.dt() == 1.0j * x)

# solve the equations
g.solve(disp = False)

print(x.value)

If I try to run this code, I expect to find the standard complex exponential. But instead, I get the following error:

File "gekko.py", line 2185, in solve
    raise Exception(response)
Exception:  @error: Model Expression
 *** Error in syntax of function string: Missing operator

Position: 9
 $v1-(((1j)*(v1)))

Could you confirm that gekko cannot handle complex numbers? And maybe suggest another python DAE solver that does?

Thank you so much!

Gekko does not natively handle complex numbers. The automatic differentiation and gradient-based solvers haven't been programmed with that in mind. As you discussed in the comments, there are workarounds to solve complex number problems by splitting the variable. There are additional suggestions at Application of complex numbers in Linear Programming?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM