polyfit - uncertainty on coefficient.
Afficher commentaires plus anciens
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 commentaires
Matt J
le 2 Oct 2012
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
le 2 Oct 2012
Star Strider
le 2 Oct 2012
Do you have the Statistics Toolbox?
Steph
le 2 Oct 2012
Réponse acceptée
Plus de réponses (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);
1 commentaire
Steph
le 2 Oct 2012
Catégories
En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!