Least-squares line fitting: Difference between revisions

From JSXGraph Wiki
(New page: <jsxgraph width="600" height="600"> var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox:[-5,5,5,-5], keepaspectratio:true}); var i, p = [], angle, co, si, delta = 0.8; // Random points...)
 
No edit summary
Line 1: Line 1:
<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});
var i, p = [], angle, co, si, delta = 0.8;
var i, p = [], angle, xr, yr, delta = 0.8;


// Random points are constructed which lie roughly on a circle
// Random points are constructed which lie roughly on a line
// of radius 4 having the origin as center.
// defined by y = 0.3*x+1.
// delta*0.5 is the maximal distance in x- and y- direction of the random
// delta*0.5 is the maximal distance in y-direction of the random
// points from the circle line.
// points from the line.
brd.suspendUpdate();
brd.suspendUpdate();
for (i=0;i<100;i++) {
for (i=0;i<100;i++) {
   angle = Math.random()*2*Math.PI;
   xr = 10*(Math.random()-0.5);
 
   yr = xr*0.3+delta*(Math.random()-0.5) +1.0;
  co = 4*Math.cos(angle)+delta*(Math.random()-0.5);
   p.push(brd.create('point',[xr, yr], {withLabel:false}));
   si = 4*Math.sin(angle)+delta*(Math.random()-0.5);
   p.push(brd.create('point',[co, si], {withLabel:false}));
}
}
brd.unsuspendUpdate();
brd.unsuspendUpdate();

Revision as of 19:18, 5 November 2010