Least-squares line fitting: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 1: Line 1:
This little JXSGraph application finds the line - described by homogeneous coordinates [a,b,1] - that minimizes
:<math> \sum_{i=1}^n (a_ix_i+b_iy_i+1)^2.</math>
<jsxgraph width="600" height="600">
<jsxgraph width="600" height="600">
var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox:[-5,5,5,-5], keepaspectratio:true});
var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox:[-5,5,5,-5], keepaspectratio:true});
Line 8: Line 12:
// points from the line.
// points from the line.
brd.suspendUpdate();
brd.suspendUpdate();
for (i=0;i<3;i++) {
for (i=0;i<1000;i++) {
   xr = 10*(Math.random()-0.5);
   xr = 10*(Math.random()-0.5);
   yr = 0.3*xr+delta*(Math.random()-0.5) +1.0;
   yr = 0.3*xr+delta*(Math.random()-0.5) +1.0;

Revision as of 19:39, 5 November 2010

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

[math]\displaystyle{ \sum_{i=1}^n (a_ix_i+b_iy_i+1)^2. }[/math]