Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I apply additional constraints to polyfit?

80 views
Skip to first unread message

exmachina zhao

unread,
May 20, 2009, 3:33:01 PM5/20/09
to
I have some linear data set and I want to fit it to a second order polynomial equation a+bx+cx^2, but b=0, so really I want to fit it to a+cx^2

Tips?

Steven Lord

unread,
May 20, 2009, 5:14:17 PM5/20/09
to

"exmachina zhao" <yto...@yahoo.com> wrote in message
news:gv1ltd$k27$1...@fred.mathworks.com...

If you don't want to fit the full polynomial, you can't use POLYFIT.
Instead, create the data matrix yourself with the terms you want and use
backslash.


x = (1:10).';
a = 5;
c = 2;
y = a+c*x.^2;
M = [x.^2, ones(size(x))]; % M*[c; a] = y
coeffs = M\y
differenceInA = a - coeffs(2)
differenceInC = c - coeffs(1)


The two difference* variables should be small.

--
Steve Lord
sl...@mathworks.com


John D'Errico

unread,
May 20, 2009, 11:49:01 PM5/20/09
to
"exmachina zhao" <yto...@yahoo.com> wrote in message <gv1ltd$k27$1...@fred.mathworks.com>...

> I have some linear data set and I want to fit it to a second order polynomial equation a+bx+cx^2, but b=0, so really I want to fit it to a+cx^2
>
> Tips?

You can also use my polyfitn, which allows yo to
explicitly specify the model.

http://www.mathworks.com/matlabcentral/fileexchange/10065

John

0 new messages