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 中查找有关 Exploration and Visualization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!