error message using polyfit (nonlinear regression)

조회 수: 20 (최근 30일)
Locks
Locks 2013년 4월 20일
hi,
I get the following error meesage:
Warning: Polynomial is not unique; degree >= number of data points.
> In polyfit at 71
In deltaAdjustment at 27
In run at 74
The code I am using is the following:
for putCall =1:2
dataPutCall = data16(data16(:,3)==putCall,:);
dates=unique(dataPutCall(:,6));
for i=1:length(dates)
date=dates(i);
dataDate = dataPutCall(dataPutCall(:,6) == date,:);
Ts = unique(dataDate(:,5));
for indexT = 1:length(Ts)
T = Ts(indexT);
dataT = dataDate(dataDate(:,5) == T,:);
number=dataT(:,13);
x= dataT(:,2);
y=dataT(:,10);
p = polyfit(x,y,2);
f = polyval(p,x);
a=p(3);
b=p(2);
c=p(1);
SlopeSkew(number)=b+2*c.*x;
Slope=SlopeSkew';
end
end
end
I have used this code for a smaller matrix and there is was worked perfectly but not it seems as something is not working correctly and I am unsure what excatly it is

채택된 답변

bym
bym 2013년 4월 20일
I think it is obvious from the message; you don't have a enough data points to fit the polynomial uniquely. Like fitting a line through just one point, there are many solutions
x=[1,2];
y = [2,8];
polyfit(x,y,2)
Warning: Polynomial is not unique; degree >= number of data points.
> In polyfit at 72
  댓글 수: 3
Walter Roberson
Walter Roberson 2013년 4월 21일
Yes, at least n+1 points for degree n.
Locks
Locks 2013년 4월 21일
perfect, thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Polynomials에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by