Polynomial regression II: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
No edit summary |
||
(2 intermediate revisions by one other user not shown) | |||
Line 5: | Line 5: | ||
brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox:[-2, 100, 220, -70], grid: false, axis:true}); | brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox:[-2, 100, 220, -70], grid: false, axis:true}); | ||
brd.suspendUpdate(); | brd.suspendUpdate(); | ||
deg = brd. | deg = brd.create('slider',[[10,90],[100,90],[1,1,10]],{name:'degree',snapWidth:1}); | ||
s = brd. | s = brd.create('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. | pointlist.push(brd.create('point', [function() { return 200*Math.random(); }, function() { return s.Value()*30*Math.random()+20;}], { style:4, strokecolor:"#0000a0", name:" "})); | ||
} | } | ||
brd.unsuspendUpdate(); | brd.unsuspendUpdate(); | ||
regression = JXG.Math.Numerics.regressionPolynomial(deg,pointlist); | regression = JXG.Math.Numerics.regressionPolynomial(deg,pointlist); | ||
reg = brd. | reg = brd.create('functiongraph',[regression],{strokeColor:'green'}); | ||
t = brd. | t = brd.create('text',[20,-40, | ||
function(){ return "r(x) = " + regression.getTerm();} | function(){ return "r(x) = " + regression.getTerm();} | ||
], | ], | ||
Line 23: | Line 23: | ||
===The underlying JavaScript code=== | ===The underlying JavaScript code=== | ||
<source lang=" | <source lang="javascript"> | ||
brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox:[-2, 100, 220, -70], grid: false, axis:true}); | brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox:[-2, 100, 220, -70], grid: false, axis:true}); | ||
brd.suspendUpdate(); | brd.suspendUpdate(); | ||
deg = brd. | deg = brd.create('slider',[[10,90],[100,90],[1,1,10]],{name:'degree',snapWidth:1}); | ||
s = brd. | s = brd.create('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. | pointlist.push(brd.create('point', [function() { return 200*Math.random(); }, function() { return s.Value()*30*Math.random()+20;}], { style:4, strokecolor:"#0000a0", name:" "})); | ||
} | } | ||
brd.unsuspendUpdate(); | |||
regression = JXG.Math.Numerics.regressionPolynomial(deg,pointlist); | regression = JXG.Math.Numerics.regressionPolynomial(deg,pointlist); | ||
reg = brd. | reg = brd.create('functiongraph',[regression],{strokeColor:'green'}); | ||
t = brd. | t = brd.create('text',[20,-40, | ||
function(){ return "r(x) = " + regression.getTerm();} | function(){ return "r(x) = " + regression.getTerm();} | ||
], | ], | ||
{strokeColor:'black',fontSize:'14px'}); | {strokeColor:'black',fontSize:'14px'}); | ||
</source> | </source> | ||
[[Category:Examples]] | [[Category:Examples]] |
Latest revision as of 11:48, 8 June 2011
Here are 30 randomly distributed points. The range of these points can be adjusted by the slider 'scale'. Through these points a regression polynomial is computed. The degree of this polynomial can be adjusted by the slider 'degree'.
The underlying JavaScript code
brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox:[-2, 100, 220, -70], grid: false, axis:true});
brd.suspendUpdate();
deg = brd.create('slider',[[10,90],[100,90],[1,1,10]],{name:'degree',snapWidth:1});
s = brd.create('slider',[[10,70],[100,70],[0,1,3]],{name:'scale'});
pointlist = [];
for (i=0; i<30;i++) {
pointlist.push(brd.create('point', [function() { return 200*Math.random(); }, function() { return s.Value()*30*Math.random()+20;}], { style:4, strokecolor:"#0000a0", name:" "}));
}
brd.unsuspendUpdate();
regression = JXG.Math.Numerics.regressionPolynomial(deg,pointlist);
reg = brd.create('functiongraph',[regression],{strokeColor:'green'});
t = brd.create('text',[20,-40,
function(){ return "r(x) = " + regression.getTerm();}
],
{strokeColor:'black',fontSize:'14px'});