Difference between revisions of "Riemann sums"
From JSXGraph Wiki
Jump to navigationJump to searchA 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) |
||
(16 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
+ | <html> | ||
+ | <!--<script type="text/javascript" src="http://korpelainen.net/js/AM1.js"></script>--> | ||
+ | </html> | ||
<html> | <html> | ||
<form>Riemann sum type: <select id="sumtype"> | <form>Riemann sum type: <select id="sumtype"> | ||
Line 4: | Line 7: | ||
<option value='right'> right | <option value='right'> right | ||
<option value='middle'> middle | <option value='middle'> middle | ||
− | <option value=' | + | <option value='trapezoidal'> trapezoidal |
+ | <option value='simpson'> simpson | ||
<option value='lower'> lower | <option value='lower'> lower | ||
<option value='upper'> upper | <option value='upper'> upper | ||
</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, | + | var brd = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox: [-8, 4, 8, -4]}); |
− | var s = brd. | + | var s = brd.create('slider',[[1,3],[5,3],[1,10,50]],{name:'n',snapWidth:1}); |
− | var a = brd. | + | var a = brd.create('slider',[[1,2],[5,2],[-10,-3,0]],{name:'start'}); |
− | var b = brd. | + | 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. | + | var plot = brd.create('functiongraph',[f,function(){return a.Value();}, function(){return b.Value();}]); |
− | var os = brd. | + | var os = brd.create('riemannsum',[f, |
− | function(){ return s.Value();}, function(){ return | + | function(){ return s.Value();}, function(){ return document.getElementById('sumtype').value;}, |
function(){return a.Value();}, | function(){return a.Value();}, | ||
function(){return b.Value();} | function(){return b.Value();} | ||
Line 24: | Line 29: | ||
{fillColor:'#ffff00', fillOpacity:0.3}); | {fillColor:'#ffff00', fillOpacity:0.3}); | ||
− | brd. | + | brd.create('text',[-6,-3,function(){ return 'Sum='+(JXG.Math.Numerics.riemannsum(f,s.Value(),document.getElementById('sumtype').value,a.Value(),b.Value())).toFixed(4); }]); |
</jsxgraph> | </jsxgraph> | ||
===The underlying JavaScript code=== | ===The underlying JavaScript code=== | ||
− | <source lang=" | + | <source lang="javascript"> |
+ | 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='+(JXG.Math.Numerics.riemannsum(f,s.Value(),document.getElementById('sumtype').value,a.Value(),b.Value())).toFixed(4); }]); | ||
</source> | </source> | ||
+ | |||
[[Category:Examples]] | [[Category:Examples]] | ||
[[Category:Calculus]] | [[Category:Calculus]] |
Latest revision as of 14:13, 11 July 2018
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='+(JXG.Math.Numerics.riemannsum(f,s.Value(),document.getElementById('sumtype').value,a.Value(),b.Value())).toFixed(4); }]);