Created
December 9, 2016 02:41
-
-
Save f-ewald/710d56409f83b1c4ad0cb757be993598 to your computer and use it in GitHub Desktop.
Basic scipy example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy import optimize | |
def objective_function(x): | |
return x[0] + x[1] | |
def constraint1(x): | |
# x + y == 12 | |
return x[0] + x[1] - 12 | |
def constraint2(x): | |
# X = 2 * Y | |
return x[0] - x[1] * 2 | |
c1 = {'type': 'eq', 'fun': constraint1} | |
c2 = {'type': 'eq', 'fun': constraint2} | |
constraint_list = [c1, c2] | |
start_guess = (8,4) | |
print optimize.minimize(objective_function, start_guess, | |
constraints=constraint_list, method='SLSQP') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment