Difference between revisions of "Riemann sums"

From JSXGraph Wiki
Jump to: navigation, search
Line 17: Line 17:
  
 
var brd = JXG.JSXGraph.initBoard('box', {axis:true, originX: 400, originY: 200, grid:true, unitX: 50, unitY: 50});
 
var brd = JXG.JSXGraph.initBoard('box', {axis:true, originX: 400, originY: 200, grid:true, unitX: 50, unitY: 50});
var s = brd.createElement('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.createElement('slider',[[1,2],[5,2],[-10,-3,0]],{name:'start'});
+
var a = brd.create('slider',[[1,2],[5,2],[-10,-3,0]],{name:'start'});
var b = brd.createElement('slider',[[1,1],[5,1],[0,Math.PI,10]],{name:'end'});
+
var b = brd.create('slider',[[1,1],[5,1],[0,Math.PI,10]],{name:'end'});
 
var f = function(x){ return Math.sin(x); };
 
var f = function(x){ return Math.sin(x); };
var plot = brd.createElement('functiongraph',[f,function(){return a.Value();}, function(){return b.Value();}]);
+
var plot = brd.create('functiongraph',[f,function(){return a.Value();}, function(){return b.Value();}]);
  
var os = brd.createElement('riemannsum',[f,  
+
var os = brd.create('riemannsum',[f,  
 
     function(){ return s.Value();}, function(){ return document.getElementById('sumtype').value;},
 
     function(){ return s.Value();}, function(){ return document.getElementById('sumtype').value;},
 
     function(){return a.Value();},  
 
     function(){return a.Value();},  
Line 30: Line 30:
 
     {fillColor:'#ffff00', fillOpacity:0.3});
 
     {fillColor:'#ffff00', fillOpacity:0.3});
  
brd.createElement('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); }]);
  
 
brd.create('text',[3,-3,'`sum_(i=0)^n i^2`']);
 
brd.create('text',[3,-3,'`sum_(i=0)^n i^2`']);
Line 39: Line 39:
 
<source lang="xml">
 
<source lang="xml">
 
<jsxgraph width="800" height="400" box="box">
 
<jsxgraph width="800" height="400" box="box">
 +
 
JXG.Options.text.useASCIIMathML = true;
 
JXG.Options.text.useASCIIMathML = true;
  
 
var brd = JXG.JSXGraph.initBoard('box', {axis:true, originX: 400, originY: 200, grid:true, unitX: 50, unitY: 50});
 
var brd = JXG.JSXGraph.initBoard('box', {axis:true, originX: 400, originY: 200, grid:true, unitX: 50, unitY: 50});
var s = brd.createElement('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.createElement('slider',[[1,2],[5,2],[-10,-3,0]],{name:'start'});
+
var a = brd.create('slider',[[1,2],[5,2],[-10,-3,0]],{name:'start'});
var b = brd.createElement('slider',[[1,1],[5,1],[0,Math.PI,10]],{name:'end'});
+
var b = brd.create('slider',[[1,1],[5,1],[0,Math.PI,10]],{name:'end'});
 
var f = function(x){ return Math.sin(x); };
 
var f = function(x){ return Math.sin(x); };
var plot = brd.createElement('functiongraph',[f,function(){return a.Value();}, function(){return b.Value();}]);
+
var plot = brd.create('functiongraph',[f,function(){return a.Value();}, function(){return b.Value();}]);
  
var os = brd.createElement('riemannsum',[f,  
+
var os = brd.create('riemannsum',[f,  
 
     function(){ return s.Value();}, function(){ return document.getElementById('sumtype').value;},
 
     function(){ return s.Value();}, function(){ return document.getElementById('sumtype').value;},
 
     function(){return a.Value();},  
 
     function(){return a.Value();},  
Line 55: Line 56:
 
     {fillColor:'#ffff00', fillOpacity:0.3});
 
     {fillColor:'#ffff00', fillOpacity:0.3});
  
brd.createElement('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); }]);
  
 
brd.create('text',[3,-3,'`sum_(i=0)^n i^2`']);
 
brd.create('text',[3,-3,'`sum_(i=0)^n i^2`']);

Revision as of 08:50, 22 July 2010

Riemann sum type:

The underlying JavaScript code

<jsxgraph width="800" height="400" box="box">

JXG.Options.text.useASCIIMathML = true;

var brd = JXG.JSXGraph.initBoard('box', {axis:true, originX: 400, originY: 200, grid:true, unitX: 50, unitY: 50});
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); }]);

brd.create('text',[3,-3,'`sum_(i=0)^n i^2`']);
</jsxgraph>