This is the mail archive of the gsl-discuss@sources.redhat.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: minimize and cspline


On Fri, 10 Oct 2003, Jeff Spirko wrote:

] On Fri, Oct 10, 2003 at 10:55:20AM +0200, Zunbeltz Izaola wrote:
] > On Thu, 9 Oct 2003, Alan Aspuru-Guzik wrote:
] > > What I would do, is create a gsl_vector for the data points you have.
] > > And then find the maximium element using:
] > > http://sources.redhat.com/gsl/ref/gsl-ref_8.html#SEC165
]
] > The point is that the maximun of the array is not the maximum of a
] > "good enough" (smooth) function that fit this point. I'm in the
] > way to solve this problem. I didn't realize that i can use
] > sl_spline_eval() in the function to be maximized, wrapping it in a
] > fuction type with parameters =0
]
] Remember that you can find the max/min of a cubic spline
] analytically.  I would post code to do this, but I lost the hard
] drive it was on. :-(
]

I think for this problem, interpolating to find a maximum, you don't
necessarily want splines, which are designed to be "pasted together"
in a smooth way to produce a curve that goes through all of your
points.  I've had to do a similar problem, finding the maximum of a
cross-correlation, and my approach was to fit a quadratic through the
three points around the maximum -- that is, the discrete maximum and
the two points on either side.  This can be done analytically, and in
fact the result is quite simple.

So if x[] is your array, and x[n] is the maximum value, then you
take the three values x[n-1], x[n], and x[n+1].  The maximum of
the quadratic will be at a point n+z where z=N/D and

N = -0.5*(x[n+1]-x[n-1])
D = x[n+1] - 2*x[n] + x[n-1]

give or take a minus sign or a factor of two somewhere...

jt



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]