|
From: | Carlo de Falco |
Subject: | Re: Weighted polyfit? |
Date: | Fri, 26 Mar 2010 12:22:47 +0100 |
On 26 Mar 2010, at 10:36, Matthias Brennwald wrote:
Dear allI am pretty sure this is something that has been discussed previously, but I was not able to find anything helpful. I'd like to fit a polynomial to my experimental data. The data have errors, and I'd like to use these errors as weights for the data values in the fit. Something like this:x = [0:10]; % x values of experimental data y = x.^2; % y values of experimental data y_err = randn(size(x)); % errors of y[p,s] = polyfit (x,y,2); % <-- replace this by something that takes into account the errors (y_err), e.g. using the weights 1./ y_err for each value in yAny hints or ideas? Matthias
Polyfit does not do this but, if your weights are all strictly positive it should be quite easy to modify it. If I am not mistaken (please check I am not completely wrong before actually using this) what you want to do corresponds to applying a diagonal left- preconditioner to the least-square vandermonde system.
i.e. add something like D = diag (sqrt(weights)); v = D*v; y = D*y; at line 87 in polyfit.m c.
[Prev in Thread] | Current Thread | [Next in Thread] |