Least-squares line fitting: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
Line 24: | Line 24: | ||
for (i=0;i<n;i++) { | for (i=0;i<n;i++) { | ||
r.push([1.0, p[i].X(), p[i].Y()]); | r.push([1.0, p[i].X(), p[i].Y()]); | ||
d = r[0]*r[0] + r[1]*r[1] + r[2]*r[2]; | d = r[i][0]*r[i][0] + r[i][1]*r[i][1] + r[i][2]*r[i][2]; | ||
r[0] = 1.0 - r[0]/d; | r[i][0] = 1.0 - r[i][0]/d; | ||
r[1] /= d; | r[i][1] /= d; | ||
r[2] /= d; | r[i][2] /= d; | ||
} | } | ||
for (j=0;j<3;j++) { | for (j=0;j<3;j++) { | ||
for (i=0,d=0;i<n;i++) { | for (i=0,d=0;i<n;i++) { |
Revision as of 16:50, 9 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...