Least-squares line fitting: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 23: Line 23:
n = p.length;
n = p.length;
for (i=0;i<n;i++) {
for (i=0;i<n;i++) {
     M.push([1.0,p[i].X(), p[i].Y(), 1.0]);
     M.push([p[i].X(), p[i].Y(), 1.0]);
     y.push(1+p[i].X()*p[i].X() + p[i].Y()*p[i].Y());
     y.push(p[i].X()*p[i].X() + p[i].Y()*p[i].Y());
}
}


Line 40: Line 40:
// and the radius r and draw the circle.
// and the radius r and draw the circle.
//var zm = z[0]*0.5;
//var zm = z[0]*0.5;
var xm = z[1]*0.5;
var xm = z[0]*0.5;
var ym = z[2]*0.5;
var ym = z[1]*0.5;
var r = Math.sqrt(z[3]+xm*xm+ym*ym);
var r = Math.sqrt(z[2]+xm*xm+ym*ym);


brd.create('circle',[ [xm,ym], r]);  
brd.create('circle',[ [xm,ym], r]);  

Revision as of 11:52, 7 November 2010

This little JXSGraph application finds the line - described by homogeneous coordinates [a,b,c] - that minimizes

[math]\displaystyle{ \sum_{i=1}^n (ax_i+by_i+cz_i)^2. }[/math]

Coming soon...