By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,776 Members | 1,302 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,776 IT Pros & Developers. It's quick & easy.

Trying to minimize a function using minimize.scipy

P: 2
Hey there!

I am trying to phase a spectrum. In order to do that, I need to minimize following function of phi:

Expand|Select|Wrap|Line Numbers
  1. import numpy as np
  2. from scipy.optimize import minimize
  3.  
  4. intgr = np.array([-73.53, -174.06, -156.59, -221.12, -219.65, -252.18, -289.71, -260.24, -271.77, -302.3 , -314.83, -358.36, -320.89, -280.42, -295.95, -338.48, -230.01, -234.54, -263.07, -248.6 , -249.13, -325.66, -329.19, -327.72, -326.25, -165.78, 30.69, 384.16, 871.63, 1341.1 , 1733.57, 2123.04, 2234.51, 2281.98, 2364.45, 2312.92, 2216.39, 2153.86, 2068.33, 2003.8 , 1929.27, 1992.74, 2024.21, 2025.68, 2015.15, 2068.62, 2110.09, 2167.56, 2234.03, 2335.5 , 2355.97])
  5. intgi = np.array([94.09, 146.18, 160.27, 126.36, 98.45, 128.54, 174.63, 159.72, 153.81, 174.9, 157.99, 155.08, 213.17, 219.26, 218.35, 207.44, 196.53, 179.62, 158.71, 143.8, 119.89, 17.98, -91.93, -168.84, -341.75, -573.66, -749.57, -928.48, -985.39, -959.3, -895.21, -768.12, -485.03, -396.94, -313.85, -113.76, -56.67, -56.58, -46.49, -21.4, -9.31, 33.78, 62.87, 112.96, 115.05, 96.14, 95.23, 126.32, 99.41, 120.5, 0.])
  6.  
  7. def intf(phi):
  8.   return intgi*np.sin(phi) - intgr*np.cos(phi)
  9.  
  10. phi0 = 0.
  11. res = minimize(intf, phi0, method='nelder-mead', options={'xtol': 1e-8, 'disp': True})


I have seen this done on numerous examples on the internet, but it doesn't work for me, and I can't figure out why... Here is the error I get:

Traceback (most recent call last):
File "./test", line 13, in <module>
res = minimize(intf, phi0, method='nelder-mead', options={'xtol': 1e-8, 'disp': True})
File "/usr/lib64/python2.7/site-packages/scipy/optimize/_minimize.py", line 342, in minimize
return _minimize_neldermead(fun, x0, args, callback, **options)
File "/usr/lib64/python2.7/site-packages/scipy/optimize/optimize.py", line 415, in _minimize_neldermead
fsim[0] = func(x0)
ValueError: setting an array element with a sequence.

Thanks!
Feb 25 '14 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.