Search code examples
pythonmatlabcallodegekko

How to call GEKKO correctly from Matlab


I found a function for calling python from Matlab. So, I tried to use this function for calling GEKKO package from Matlab for solving ODE. I have gotten an error for defining a gekko option (remote=true) as function or variable.

I opened Matlab with Anaconda Prompt.

m = py.gekko.GEKKO(remote==True);
m.time = py.numpy.linspace(0,20,100);
k = 10;
y = m.Var(5.0);
t = m.Param(m.time);
m.Equation(k*y.dt()==-t*y);
m.options.IMODE = 4;
m.solve(disp==True)

time = cellfun(@double,cell(m.time.tolist()));
y = cellfun(@double,cell(y.VALUE.value));
plot(time,y)
xlabel('Time')
ylabel('y')

error message Undefined function or variable 'remote'.

Error in ODE_gekko_matlab (line 5) m = py.gekko.GEKKO(remote==True); % Solve on local machine


Solution

  • Check this link for how to use pyargs in Matlab. Try using m = py.gekko.GEKKO(pyargs('remote' , 'True'));

    m = py.gekko.GEKKO(pyargs('remote' , 'True'));
    m.time = py.numpy.linspace(0,20,100);
    k = 10;
    y = m.Var(5.0);
    t = m.Param(m.time);
    m.Equation(k*y.dt()==-t*y);
    m.options.IMODE = 4;
    m.solve(disp==True)
    
    time = cellfun(@double,cell(m.time.tolist()));
    y = cellfun(@double,cell(y.VALUE.value));
    plot(time,y)
    xlabel('Time')
    ylabel('y')
    
    

    enter image description here