# Calling User defined Matlab Functions in Python with Matlab.engine API

I am trying to combine Matlab and python scripts and figure out if I can achieve a better solution in terms of the solver-runtime. A very simple optimization problem is used just for now. But I got in trouble when I run optimizer in python. Here is Matlab code that includes the objective function:

function [f] = objective(x)
f = x(1)^2 + x(2)^2;
end


And this is the python script:

from scipy.optimize import minimize
import matlab.engine
import matlab

eng=matlab.engine.start_matlab()

x0=[5,10]
x0=matlab.double(x0)

def const(x):
return x[0]+x[1]-1

con1={'type':'eq','fun':const}

result=minimize(eng.objective,x0,constraints=con1)


When I run this script, I always get the following error;

  File "C:\Users\ASUS\Anaconda3\lib\site-packages\matlab\engine\matlabengine.py", line 64, in __call__
future = pythonengine.evaluateFunction(self._engine()._matlab,

TypeError: unsupported Python data type: numpy.ndarray


Even though I pass double to initial values, minimize is having a problem with the data type. Do you have any idea to get this thing work?