fitting arbitrary nth degree polynomial?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

fitting arbitrary nth degree polynomial?

Bill Christens-Barry
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.

Thanks.

Bill Christens-Barry
Reply | Threaded
Open this post in threaded view
|

Re: fitting arbitrary nth degree polynomial?

Wayne Rasband
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
Reply | Threaded
Open this post in threaded view
|

Re: fitting arbitrary nth degree polynomial?

Bill Christens-Barry
In reply to this post by Bill Christens-Barry
Thanks, Wayne, for this explanation of how curve fitting can be done in a macro. I would like in
particular to be able to suppress some terms in polynomials, for example the linear term in a 2nd
degree polynomial, so that the result is a parabola plus constant term. I've started looking at the
source to see how I can do this.

Bill Christens-Barry

On Mon, 5 Jan 2009 16:50:42 -0500, Wayne Rasband <[hidden email]> wrote:

>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