Riemann sum III: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<math>: f: R\to R, x\mapsto x^2 </math>
Appromximate the integral of
<math>f: R\to R, x\mapsto x^2 </math>
<html>
<html>
<form>Riemann sum type: <select id="sumtype" >
<form>Riemann sum type: <select id="sumtype" onChange="brd.update()">
<option value='left' selected> left
<option value='left' selected> left
<option value='right'> right
<option value='right'> right
<option value='middle'> middle
<option value='middle'> middle
<option value='trapezodial'> trapezodial
<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, boundingbox:[-2,40,8,-5]});
var brd = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox:[-2,40,8,-5]});
var s = brd.create('slider',[[1,30],[5,30],[1,50,500]],{name:'n',snapWidth:1});
var s = brd.create('slider',[[-1,30],[2,30],[3,50,500]],{name:'n',snapWidth:1});
var a = brd.create('slider',[[1,20],[5,20],[-10,0,0]],{name:'start'});
var a = brd.create('slider',[[-1,20],[2,20],[-10,0,0]],{name:'start'});
var b = brd.create('slider',[[1,10],[5,10],[0,6,10]],{name:'end'});
var b = brd.create('slider',[[-1,10],[2,10],[0,6,10]],{name:'end'});
var f = function(x){ return x*x; };
var f = function(x){ return x*x; };
var plot = brd.create('functiongraph',[f,function(){return a.Value();}, function(){return b.Value();}]);
var plot = brd.create('functiongraph',[f,function(){return a.Value();}, function(){return b.Value();}]);
Line 24: Line 27:
     ],  
     ],  
     {fillColor:'#ffff00', fillOpacity:0.3});
     {fillColor:'#ffff00', fillOpacity:0.3});
/*
 
brd.createElement('text',[-6,-4,function(){ return 'Sum='+(brd.riemannsum(f,s.Value(),document.getElementById('sumtype').value,a.Value(),b.Value())).toFixed(4); }]);
brd.create('text',
*/
      [1,35,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="xml">
<source lang="xml">
<jsxgraph width="800" height="400" box="box">
<form>Riemann sum type: <select id="sumtype" onChange="brd.update()">
</jsxgraph>
<option value='left' selected> left
<option value='right'> right
<option value='middle'> middle
<option value='trapezoidal'> trapezoidal
<option value='simpson'> simpson
<option value='lower'> lower
<option value='upper'> upper
</select></form>
</source>
 
<source lang="javascript">
var brd = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox:[-2,40,8,-5]});
var s = brd.create('slider',[[-1,30],[2,30],[3,50,500]],{name:'n',snapWidth:1});
var a = brd.create('slider',[[-1,20],[2,20],[-10,0,0]],{name:'start'});
var b = brd.create('slider',[[-1,10],[2,10],[0,6,10]],{name:'end'});
var f = function(x){ return x*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',
      [1,35,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 09:16, 7 August 2013

Appromximate the integral of [math]\displaystyle{ f: R\to R, x\mapsto x^2 }[/math]

Riemann sum type:

The underlying JavaScript code

<form>Riemann sum type: <select id="sumtype" onChange="brd.update()">
<option value='left' selected> left
<option value='right'> right
<option value='middle'> middle
<option value='trapezoidal'> trapezoidal
<option value='simpson'> simpson
<option value='lower'> lower
<option value='upper'> upper
</select></form>
var brd = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox:[-2,40,8,-5]});
var s = brd.create('slider',[[-1,30],[2,30],[3,50,500]],{name:'n',snapWidth:1});
var a = brd.create('slider',[[-1,20],[2,20],[-10,0,0]],{name:'start'});
var b = brd.create('slider',[[-1,10],[2,10],[0,6,10]],{name:'end'});
var f = function(x){ return x*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',
      [1,35,function(){ return 'Sum='+(JXG.Math.Numerics.riemannsum(f,s.Value(),document.getElementById('sumtype').value,a.Value(),b.Value())).toFixed(4); }]);