Skip to content

Instantly share code, notes, and snippets.

@f-ewald
Created December 9, 2016 02:41
Show Gist options
  • Save f-ewald/710d56409f83b1c4ad0cb757be993598 to your computer and use it in GitHub Desktop.
Save f-ewald/710d56409f83b1c4ad0cb757be993598 to your computer and use it in GitHub Desktop.
Basic scipy example
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