octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: polyfit: add the ability to specify the polynomial template


From: Ben Abbott
Subject: Re: polyfit: add the ability to specify the polynomial template
Date: Sat, 04 Feb 2012 13:35:00 -0500

On Feb 4, 2012, at 10:52 AM, CdeMills wrote:

> bpabbott wrote
> 
>> I like your idea. I've been thinking of adding weights to polyfit as well.
>> I haven't started on it, but I think the important part is embodied in one
>> line.
>> 
>> -    p = r \ (q' * y);
>> +    p = (r \ (q' * (w .* y)));
>> 
>> My work on this isn't at the top of my list. If you're inclined to add
>> this as well, please do.
> 
> Hello Ben,
> why not ? Could you please provide some data where weighting/not weighting
> makes a difference ?

Adding the weights allows for a weighted least squares solution.

One example where I prefer weighted least squares is when I'm fitting to 
empirical data, and have estimates for the error of the underlying data.

For an independent variable "x" and dependent data "y" with error "ey" the 
weighted fit could take on the syntax below.

        w = median (ey(:)) ./ ey(:));
        p = polyfit (x(:), y(:), order, w)

Then plot of the data and fit ...

        h = errorbar (x, y, ey);
        set (h, "linestyle", "none")
        hold on
        plot (x, polyval (p, x), "-")

hmmm ... maybe it is a good idea to have polyfit() normalize the weighting  too?

Ben






reply via email to

[Prev in Thread] Current Thread [Next in Thread]