algorithm - How to print a value associated with a minimized residual - Python -


i have simple algorithm computing residuals of mathematical model , experimental data noise. objective find phase if amplitude , frequency known. algorithm loops on phase values (to precision of 3 decimal places) 0 2*pi. residuals each calculation of model each phase calculated. program appends each phase , residual respective lists. know can use scipy.optimize attack problem, have reasons wanting use algorithm. question is, how can retrieve phase value associated smallest residual value? program looks this:

import numpy np numpy import loadtxt  data = loadtxt('foo.txt', float)  x = data[:,0] y = data[:,1]  = 1.5 f = 0.01 p = [] phase = 0.000 residuals = []   in range(0, 6284):     p.append(phase)     model = a*np.sin(2*np.pi*f*x+phase)     res = sum((y-model)**2)     residuals.append(res)     phase += 0.001  print min(residuals) 

any on how retrieve phase value associated minimum residual helpful. thanks.

use following code

p[residuals.index(min(residuals))] 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -