2

I have a code in matlab and I want to convert it to python. The matlab code is as follows:

options = optimoptions('fmincon','algorithm','interior-point','MaxIterations',500);
[theta,feval1,exitflag]=fmincon(@function,x0,A,b,Aeq,beq,lb,ub,nonlcon,options);

I searched for equivalent functions for fmincon in Python and found Scipy.optimize.fmin, but when I tried to use it I got stuck in passing the variables. What I have so far is:

fmin(function, x0, args=Xdata, maxiter=500)

It is clear how to pass the function, the x0, and the number of iterations. but how about the other arguments (algorithm, A, b, Aeq, beq, lb, ub, and nonlcon)?

  • Since you used an interior-point algorithm in Matlab and scipy.optimize.fmin uses a (derivative-free) downhill-simplex algorithm, you should use [scipy.optimize.minimize](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html) instead. – joni Jun 17 '21 at 16:05
  • Thank you for your reply @joni, I did see this function and there are some missing arguments such as Aeq and Beq, how to pass these? Also, I saw the methods used for this function and couldn't see the 'interior-point', so is it used by default by this function? – abdullateef najem Jun 20 '21 at 13:44
  • 2
    The documentation contains several examples of how to pass the constraints, see [here](https://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html#constrained-minimization-of-multivariate-scalar-functions-minimize). You could use the 'trust-constr' method, which uses [this](https://epubs.siam.org/doi/abs/10.1137/S1052623497325107) interior-point algorithm in the presence of inequality constraints. In case you need help, please edit the answer and provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – joni Jun 20 '21 at 14:12

0 Answers0