Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Fitting the equation y=a+bx+cx^d

Subject: Fitting the equation y=a+bx+cx^d

From: David Heslop

Date: 16 Nov, 2010 05:28:03

Message: 1 of 5

Hi All,
I've got some experimental data (x,y) which from theory I know I should be able to fit using the equation y=a+b.*x+c.*x.^d. The noise level in the data is quite low, but since the problem is ill conditioned I'm having trouble obtaining reliable estimates on the coefficients (in particular d, which is the parameter of most interest). I can add some constraints to the model, both a and b must be positive and c and d should be negative. I've tried working with lsqnonlin but it seems to be very sensitive to the initial guess. Can anyone suggest a nice method to fit the equation and in particular obtain a reliable estimate of d.
Thanks in advance, Dave

Subject: Fitting the equation y

From: Rune Allnor

Date: 16 Nov, 2010 06:12:43

Message: 2 of 5

On Nov 16, 6:28 am, "David Heslop" <david_hes...@xyz.com> wrote:
> Hi All,
> I've got some experimental data (x,y) which from theory I know I should be able to fit using the equation y=a+b.*x+c.*x.^d. The noise level in the data is quite low, but since the problem is ill conditioned I'm having trouble obtaining reliable estimates on the coefficients (in particular d, which is the parameter of most interest). I can add some constraints to the model, both a and b must be positive and c and d should be negative. I've tried working with lsqnonlin but it seems to be very sensitive to the initial guess.

That's the price you pay for getting tangled up in nonlinear
problems.

> Can anyone suggest a nice method to fit the equation and in particular obtain a reliable estimate of d.

These things *are* messy. If you want 'nice' and 'reliable', find
a different carreer.

Rune

Subject: Fitting the equation y=a+bx+cx^d

From: Bruno Luong

Date: 16 Nov, 2010 06:43:05

Message: 3 of 5

"David Heslop" <david_heslop@xyz.com> wrote in message <ibt4p3$lp5$1@fred.mathworks.com>...
> Hi All,
> I've got some experimental data (x,y) which from theory I know I should be able to fit using the equation y=a+b.*x+c.*x.^d. The noise level in the data is quite low, but since the problem is ill conditioned I'm having trouble obtaining reliable estimates on the coefficients (in particular d, which is the parameter of most interest). I can add some constraints to the model, both a and b must be positive and c and d should be negative. I've tried working with lsqnonlin but it seems to be very sensitive to the initial guess. Can anyone suggest a nice method to fit the equation and in particular obtain a reliable estimate of d.

This problem is indeed nasty. However you might have a chance because when fitting with (weighted) least-squares by fixing "d", it becomes linear with respect to "a, b, c". These kinds of fitting is called "separable least-squares" and there are a bunch of papers writing on this problem. One of the most popular is combined with Gauss-Newton and use the Golub-Pereyra formula and Kaufmann simplification. In your case it's just 1D and the formula can simplify greatly.

I have used it in the pass on other problems and it gives somewhat satisfying results.

Bruno

Subject: Fitting the equation y=a+bx+cx^d

From: Bruno Luong

Date: 16 Nov, 2010 07:06:03

Message: 4 of 5

May be in 1D, brute force with FMINBND might work:

function cost = lsqd(d, x, y)

n = length(x);
M = [ones(n,1) x(:) x(:).^d];
abc = M\y(:);
res = M*abc - y(:);
cost = sum(res.^2);

end % lsqd

% Command line
% Data
x=linspace(0.1,2,50);
a = 1
b = 2
c = -1
d = -1.2
y = a+b*x+c*x.^d+0.1*randn(size(x));

dopt = fminbnd(@(d) lsqd(d,x,y), -2, -0.001)
n = length(x);
M = [ones(n,1) x(:) x(:).^d];
abc = M\y(:);
aopt = abc(1)
bopt = abc(2)
copt = abc(3)

% Bruno

Subject: Fitting the equation y=a+bx+cx^d

From: David Heslop

Date: 16 Nov, 2010 23:46:05

Message: 5 of 5

Hi Bruno,
thanks for the suggestion and the code. For a collection of test data the separable least-squares approach certainly seems to give more stable and accurate results than the other methods I was trying,
thanks again, Dave

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us