I'm trying to use
When the parameters fall out of the admissible range, return a wildly huge number (far from the data to be fitted). This will (hopefully) penalize this choice of parameters so much thatwill settle on some other admissible set of parameters as optimal.
The Nelder-Mead solver doesn't support constrained optimization, but there are several others that do.
TNC and L-BFGS-B both support only bound constraints (e.g.
x >= 0), which should be fine for your case. COBYLA and SLSQP are more flexible, supporting any combination of bounds, equality and inequality-based constraints.
You can find more detailed info about the solvers by looking at the docs for the standalone functions, e.g.
You can see my previous answer here for an example of constrained optimization using SLSQP.