I asked a while ago about polynomial curve fitting using arbitrary weighting

functions for the fitted deviates.

John d'Errico came to my rescue with FMINSEARCH. Eg, using ERF as the

weighting function, we can search for the minimal weighted sums of squares as

follows:

% perform ordinary LS fit to get a starting value for

% the coeff vector for an n-th order poly

p = polyfit(x, n);

% define function to minimise

obj = @(c) sum( erf( (y - polyval(c,x)).^2 ) );

% perform simplex hull search for optimised coeff

% vector that gives local (n+1)D minimum in obj()

optim_p = fminsearch(obj, p);

In practice the spread of the weighting function needs to be matched to the

data. The simplest way to parameterise this is to scale the deviates before

weighting them. The definition of obj() is then:

obj = @(c) sum( erf( k * (y - polyval(c, x)).^2 ) );

Now, I don't know how the Nelder-Mead algorithm used by FMINSEARCH works, but I

gather the algorithm is meant to work generically, ie, the local minimum is

found by searching numerically in each dimension, without regard to what role

the variables play in the obj() function.

Thinking along these lines led me to combine the scaling factor k with the

polynomial coefficients into a composite vector to be optimised:

obj = @(c) sum( erf( c(1) * (y - polyval(c(2:end), x)).^2 ) );

optim_c = fminsearch(obj, [k p]);

If this is successful, then:

optim_k = optim_c(1);

optim_p = optim_c(2:end);

However, it ISN'T successful. The coeffs obtained are wildy wrong. Why

doesn't it work?

Thanks

Ross