Re: fitting arbitrary nth degree polynomial?
Posted by
Wayne Rasband on
Jan 05, 2009; 9:50pm
URL: http://imagej.273.s1.nabble.com/fitting-arbitrary-nth-degree-polynomial-tp3694105p3694107.html
On Jan 5, 2009, at 3:35 PM, Bill Christens-Barry wrote:
> Does anyone know of a plugin that would allow me to fit a parabola, or
> more generally an arbitrary
> nth-degree polynomial (up to whatever n is currently supported), to
> (x, y) coordinate pairs? This
> would amount to constraining the coefficients of some terms to equal 0.
You can use the curve fitter built into ImageJ. Here is an example
macro that fits a 3rd degree polynomial to 25 data points.
n = 25;
xpoints = newArray(n);
ypoints = newArray(n);
xmin = -2;
xmax = 2;
xinc = (xmax-xmin)/(n-1);
x = xmin;
for (i=0; i<n; i++) {
xpoints[i] = x+random/6;
ypoints[i] = x*x+random/6;
x += xinc;
}
Fit.doFit("3rd Degree Polynomial", xpoints, ypoints)
Fit.plot
Look at the source for the plugin that implements the
Analyze>Tools>Curve Fitting command for an example of how to do curve
fitting in a plugin.
http://rsb.info.nih.gov/ij/source/ij/plugin/frame/Fitter.java-wayne