Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

How to call GEKKO correctly from Matlab

Date: 2022-11-21 12:30:20

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 

Answer: 

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')

 


Why Matlabhelpers ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com