Least-squares line fitting: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) (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...) |
A WASSERMANN (talk | contribs) 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, | var i, p = [], angle, xr, yr, delta = 0.8; | ||
// Random points are constructed which lie roughly on a | // Random points are constructed which lie roughly on a line | ||
// | // defined by y = 0.3*x+1. | ||
// delta*0.5 is the maximal distance in | // delta*0.5 is the maximal distance in y-direction of the random | ||
// points from the | // points from the line. | ||
brd.suspendUpdate(); | brd.suspendUpdate(); | ||
for (i=0;i<100;i++) { | for (i=0;i<100;i++) { | ||
xr = 10*(Math.random()-0.5); | |||
yr = xr*0.3+delta*(Math.random()-0.5) +1.0; | |||
p.push(brd.create('point',[xr, yr], {withLabel:false})); | |||
p.push(brd.create('point',[ | |||
} | } | ||
brd.unsuspendUpdate(); | brd.unsuspendUpdate(); |