简体   繁体   中英

Scipy minimization with multiple constraints

I want to minimize a functional using the scipy module scipy.optimize and I'm struggling to understand how to implement my constraints. The extremal points of my solution must be exactly zero and one, so right now I'm imposing

cons = ({'type': 'eq',
          'fun' : lambda x: x[0]}, #the initial point is 0
        {'type': 'eq',
          'fun' : lambda x: x[-1]-1.}) #the final point is 1

but I also need every other point to be strictly higher than 0 and smaller than 1. How can I explicitly add this further constraint for all the other points of my array?

If x[0] must be 0 and x[-1] must be 1, you are not optimising them, so you can just set them to those values inside your function, no need to add constraints. For the other points, set bounds between 0 and 1 with bounds keyword :

bounds=[(0, 1), (0, 1),...]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM