Riemann sums: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) (New page: <html> <form>Riemann sum type: <select id="sumtype"> <option value='left' selected> left <option value='right'> right <option value='middle'> middle <option value='trapezodial'> trapezodia...) |
A WASSERMANN (talk | contribs) No edit summary |
||
Line 24: | Line 24: | ||
{fillColor:'#ffff00', fillOpacity:0.3}); | {fillColor:'#ffff00', fillOpacity:0.3}); | ||
brd.createElement('text',[-6,-3,function(){ return 'Sum='+(brd.riemannsum(f,s.Value(),$('sumtype').value,a.Value(),b.Value())).toFixed(4); }] | brd.createElement('text',[-6,-3,function(){ return 'Sum='+(brd.riemannsum(f,s.Value(),$('sumtype').value,a.Value(),b.Value())).toFixed(4); }]); | ||
</jsxgraph> | </jsxgraph> | ||
===The underlying JavaScript code=== | ===The underlying JavaScript code=== | ||
<source lang="xml"> | <source lang="xml"> | ||
<jsxgraph width="800" height="400" box="box"> | |||
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'}); | |||
var a = brd.createElement('slider',[[1,2],[5,2],[-10,0,0]],{name:'start'}); | |||
var b = brd.createElement('slider',[[1,1],[5,1],[0,Math.PI,10]],{name:'end'}); | |||
var f = function(x){ return Math.sin(x); } | |||
var plot = brd.createElement('functiongraph',[f,function(){return a.Value();}, function(){return b.Value();}]); | |||
var os = brd.createElement('riemannsum',[f, | |||
function(){ return s.Value();}, function(){ return $('sumtype').value;}, | |||
function(){return a.Value();}, | |||
function(){return b.Value();} | |||
], | |||
{fillColor:'#ffff00', fillOpacity:0.3}); | |||
brd.createElement('text',[-6,-3,function(){ return 'Sum='+(brd.riemannsum(f,s.Value(),$('sumtype').value,a.Value(),b.Value())).toFixed(4); }]); | |||
</jsxgraph> | |||
</source> | </source> | ||
[[Category:Examples]] | [[Category:Examples]] | ||
[[Category:Calculus]] | [[Category:Calculus]] |
Revision as of 07:22, 4 May 2009
The underlying JavaScript code
<jsxgraph width="800" height="400" box="box">
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'});
var a = brd.createElement('slider',[[1,2],[5,2],[-10,0,0]],{name:'start'});
var b = brd.createElement('slider',[[1,1],[5,1],[0,Math.PI,10]],{name:'end'});
var f = function(x){ return Math.sin(x); }
var plot = brd.createElement('functiongraph',[f,function(){return a.Value();}, function(){return b.Value();}]);
var os = brd.createElement('riemannsum',[f,
function(){ return s.Value();}, function(){ return $('sumtype').value;},
function(){return a.Value();},
function(){return b.Value();}
],
{fillColor:'#ffff00', fillOpacity:0.3});
brd.createElement('text',[-6,-3,function(){ return 'Sum='+(brd.riemannsum(f,s.Value(),$('sumtype').value,a.Value(),b.Value())).toFixed(4); }]);
</jsxgraph>