Difference between revisions of "Riemann sums"

From JSXGraph Wiki
Jump to: navigation, search
Line 12: Line 12:
 
</select></form>
 
</select></form>
 
</html>
 
</html>
 +
 
<jsxgraph width="800" height="400" box="box">
 
<jsxgraph width="800" height="400" box="box">
 
+
var brd = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox: [-8, 4, 8, -4]});
var brd = JXG.JSXGraph.initBoard('box', {axis:true, originX: 400, originY: 200, grid:false, unitX: 50, unitY: 50});
 
 
var s = brd.create('slider',[[1,3],[5,3],[1,10,50]],{name:'n',snapWidth:1});
 
var s = brd.create('slider',[[1,3],[5,3],[1,10,50]],{name:'n',snapWidth:1});
 
var a = brd.create('slider',[[1,2],[5,2],[-10,-3,0]],{name:'start'});
 
var a = brd.create('slider',[[1,2],[5,2],[-10,-3,0]],{name:'start'});
Line 32: Line 32:
  
 
===The underlying JavaScript code===
 
===The underlying JavaScript code===
<source lang="xml">
+
<source lang="javascript">
<jsxgraph width="800" height="400" box="box">
+
var brd = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox: [-8, 4, 8, -4]});
 
 
var brd = JXG.JSXGraph.initBoard('box', {axis:true, originX: 400, originY: 200, grid:false, unitX: 50, unitY: 50});
 
 
var s = brd.create('slider',[[1,3],[5,3],[1,10,50]],{name:'n',snapWidth:1});
 
var s = brd.create('slider',[[1,3],[5,3],[1,10,50]],{name:'n',snapWidth:1});
 
var a = brd.create('slider',[[1,2],[5,2],[-10,-3,0]],{name:'start'});
 
var a = brd.create('slider',[[1,2],[5,2],[-10,-3,0]],{name:'start'});
Line 50: Line 48:
  
 
brd.create('text',[-6,-3,function(){ return 'Sum='+(brd.riemannsum(f,s.Value(),document.getElementById('sumtype').value,a.Value(),b.Value())).toFixed(4); }]);
 
brd.create('text',[-6,-3,function(){ return 'Sum='+(brd.riemannsum(f,s.Value(),document.getElementById('sumtype').value,a.Value(),b.Value())).toFixed(4); }]);
 
</jsxgraph>
 
 
</source>
 
</source>
  
 
[[Category:Examples]]
 
[[Category:Examples]]
 
[[Category:Calculus]]
 
[[Category:Calculus]]

Revision as of 14:34, 8 June 2011

Riemann sum type:

The underlying JavaScript code

var brd = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox: [-8, 4, 8, -4]});
var s = brd.create('slider',[[1,3],[5,3],[1,10,50]],{name:'n',snapWidth:1});
var a = brd.create('slider',[[1,2],[5,2],[-10,-3,0]],{name:'start'});
var b = brd.create('slider',[[1,1],[5,1],[0,Math.PI,10]],{name:'end'});
var f = function(x){ return Math.sin(x); };
var plot = brd.create('functiongraph',[f,function(){return a.Value();}, function(){return b.Value();}]);

var os = brd.create('riemannsum',[f, 
    function(){ return s.Value();}, function(){ return document.getElementById('sumtype').value;},
    function(){return a.Value();}, 
    function(){return b.Value();}
    ], 
    {fillColor:'#ffff00', fillOpacity:0.3});

brd.create('text',[-6,-3,function(){ return 'Sum='+(brd.riemannsum(f,s.Value(),document.getElementById('sumtype').value,a.Value(),b.Value())).toFixed(4); }]);