polyfit - uncertainty on coefficient.
이전 댓글 표시
Hi all,
I've got data points :
x = [0 0 5 5]; y = [0 1 4 7];
I would like to fit these data with polyfit (ax + b) and then, derive the "maximum and minimum" lines compatible with these data - that should be the uncertainty on a and b.
What I should obtain in this easy example is : y = 7/5 * x + 0 and y = 3/5 * x + 1.
I've found on this forum things about using cov and the S output of the function, but the error I got from the sqrt(...) formula doesn't give the numbers above...
Could anyone help me ?
Thanks
댓글 수: 4
Matt J
2012년 10월 2일
I don't think I get it. Are the first N/2 points the hypothetical start points of the line and the final N/2, the hypothetical end points?
What would the result be if you had data like this
x = [0 0 5 5 5.01];
y = [0 1 4 7 0];
in which the steepest sloped line is between (5,7) and (5.01,0)?
Steph
2012년 10월 2일
Star Strider
2012년 10월 2일
Do you have the Statistics Toolbox?
Steph
2012년 10월 2일
채택된 답변
추가 답변 (1개)
The problem is a 2D linear program. If you have the Optimization Toolbox, you could use LINPROG to solve it. Otherwise, the code below, applied to your original example, uses a brute force approach and relies on my lcon2vert() function available here
barwidths=[1,3];
x = [0 5];
y = [0.5 5.5];
x=x(:); y=y(:); barwidths=barwidths(:); %ensure column form
lb=y-barwidths/2; %lower bounds
ub=y+barwidths/2; %upper bounds
%Linear program data
A=[x(:), ones(size(x(:)))];
A=[A;-A];
b=[ub;-lb];
f=[1,0];
%Brute force linear program solve
V=lcon2vert(A,b);
[minslope,imin]=min(V(:,1));
[maxslope,imax]=max(V(:,1));
minParams=V(imin,:),
maxParams=V(imax,:),
Using LINPROG the final 5 lines would be replaced by:
minParams = linprog(f,A,b);
maxParams = linprog(-f,A,b);
카테고리
도움말 센터 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!