Skip to content

Instantly share code, notes, and snippets.

@feilong
Created July 23, 2015 17:56
Show Gist options
  • Select an option

  • Save feilong/b1330ed03ad0fd88d1a9 to your computer and use it in GitHub Desktop.

Select an option

Save feilong/b1330ed03ad0fd88d1a9 to your computer and use it in GitHub Desktop.
Mathematical optimization w/ Python
#!/usr/bin/env python
import numpy as np
from scipy.optimize import minimize
def cost_function(x):
return (x[0]-3)**2 + (x[1]-2)**2
x0 = [0, 0] # initial guess
method = 'nelder-mead'
res = minimize(cost_function, x0, method=method,
options={'xtol': 1e-8, 'disp': True})
print res.x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment