一部のデータの最小化を制限する必要があります (つまり、特定の範囲内で最小値を取得するため)。現在、すべてのスペースで最小値しか取得できません。たとえば、目前の問題に対する有効な可能な答えが -5<=x<=5 の範囲にしかない場合、関数の最小値が -10505 であることを fmin に教えても無駄です。可能な出力を問題の制限内に制限する必要があります。
p = [0,0,0]
fit_quad = lambda p,w: p[2]*w**2 + p[1]*w + p[0]
errfunc = lambda p,l,w: fit_quad(p,w) - l
fit, success = leastsq(errfunc, p, args=(y,x), maxfev=5000) #x and y are the input datasets
#find the minimum tilt
quad = lambda w,p: p[2]*w**2 + p[1]*w + p[0]
min_tilt = fmin(quad, 0.0, args=([fit]))[0]
#check for range violations
if min_tilt < min_angle #the minimum on the quadratic can sometimes end up negative, especially if there are not enough good points
min_tilt = 0.0
elif min_tilt > max_angle: #if things are extremely tilted the minimum of the fit quadratic can end up unrealistically high. This pulls it back.
min_tilt = max_angle
上記のように、単純に上または下にチェックを設定するだけでは十分ではないことに注意してください。範囲内にある関数の正確な部分によっては、範囲の反対側になってしまう可能性があります。