Polynomial regression II: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
Line 3: | Line 3: | ||
brd.suspendUpdate(); | brd.suspendUpdate(); | ||
deg = brd.createElement('slider',[[10,90],[100,90],[1,1,10]],{name:'degree',snapWidth:1}); | deg = brd.createElement('slider',[[10,90],[100,90],[1,1,10]],{name:'degree',snapWidth:1}); | ||
s = brd.createElement('slider',[[10,70],[100,70],[0,1,3]],{name:'scale'}); | |||
pointlist = []; | pointlist = []; | ||
for (i=0; i<30;i++) { | for (i=0; i<30;i++) { | ||
pointlist.push(brd.createElement('point', [function() { return 200*Math.random(); }, function() { return 30*Math.random()+20;}], { style:4, strokecolor:"#0000a0", name:" "})); | pointlist.push(brd.createElement('point', [function() { return 200*Math.random(); }, function() { return s.Value()*30*Math.random()+20;}], { style:4, strokecolor:"#0000a0", name:" "})); | ||
} | } | ||
regression = JXG.Math.Numerics.regressionPolynomial(deg,pointlist); | regression = JXG.Math.Numerics.regressionPolynomial(deg,pointlist); | ||
reg = brd.createElement('functiongraph',[regression],{strokeColor:'green'}); | reg = brd.createElement('functiongraph',[regression],{strokeColor:'green'}); | ||
t = brd.createElement('text',[20,40, | t = brd.createElement('text',[20,-40, | ||
function(){ return "r(x) = " + regression.getTerm();} | function(){ return "r(x) = " + regression.getTerm();} | ||
], | ], |