I have a my problem simulated in Matlab environment with a script file and corresponding function file for the same. I need to use them in GEKKO python. Is there a way to export those matlab files directly to GEKKO environment?
I have a my problem simulated in Matlab environment with a script file and corresponding function file for the same. I need to use them in GEKKO python. Is there a way to export those matlab files directly to GEKKO environment?
There are a couple ways to help with the conversion.
Python
from gekko import GEKKO
# Initialize Model
m = GEKKO()
# Initialize Variables
x = m.Var() # define new variable
y = m.Var() # default=0
# Define Equations
m.Equation(3*x+2*y==1)
m.Equation(x+2*y==0)
# Solve
m.solve()
# Print solution
print('x: ' + str(x.value[0]))
print('y: ' + str(y.value[0]))
MATLAB
% start Matlab from Anaconda prompt
close all; clear;
% Solve linear equations
% Initialize Model
m = py.gekko.GEKKO();
% Initialize Variables
x = m.Var(); % define new variable
y = m.Var(); % default=0
% Define Equations
m.Equation(3*x+2*y==1);
m.Equation(x+2*y==0);
% Solve
m.solve();
% Extract values from Python lists using curly brackets
disp(['x: ' num2str(x.VALUE{1})]);
disp(['y: ' num2str(y.VALUE{1})]);
Other than that, there are no automatic translation tools from MATLAB to Python Gekko. These optimization tutorials with the same problem in MATLAB and Python may help.