JSXGraph logo
JSXGraph
JSXGraph share

Share

Riemann sum III
QR code
<iframe 
    src="https://jsxgraph.org/share/iframe/riemann-sum-iii" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: Riemann sum III" 
    allowfullscreen
></iframe>
This code has to
Riemann sum type: <select id="sumtype" onChange="board.update()">
    <option value='lower' selected> lower
    <option value='upper'> upper
    <option value='left'> left
    <option value='right'> right
    <option value='middle'> middle
    <option value='trapezoidal'> trapezoidal
    <option value='simpson'> simpson
</select>

<div id="board-0-wrapper" class="jxgbox-wrapper " style="width: 100%; ">
   <div id="board-0" class="jxgbox" style="aspect-ratio: 1 / 1; width: 100%;" data-ar="1 / 1"></div>
</div>

<script type = "text/javascript"> 
    /*
    This example is licensed under a 
    Creative Commons Attribution ShareAlike 4.0 International License.
    https://creativecommons.org/licenses/by-sa/4.0/
    
    Please note you have to mention 
    The Center of Mobile Learning with Digital Technology
    in the credits.
    */
    
    const BOARDID = 'board-0';

    var board = JXG.JSXGraph.initBoard(BOARDID, { axis: true, boundingbox: [-2, 40, 8, -5] });
    
    var s = board.create('slider', [[1, 30], [6, 30], [3, 5, 50]], { name: 'n', snapWidth: 1 });
    var a = board.create('slider', [[1, 25], [6, 25], [-10, 0, 0]], { name: 'start' });
    var b = board.create('slider', [[1, 20], [6, 20], [0, 6, 10]], { name: 'end' });
    
    var f = function(x) { return -x * (x - 6); };
    var plot = board.create('functiongraph', [f, function() { return a.Value(); }, function() { return b.Value(); }]);
    
    var os = board.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 });
    
    board.create('text',
          [1, 35, function() { return 'approx. sum = ' + (JXG.Math.Numerics.riemannsum(f, s.Value(), document.getElementById('sumtype')
                .value, a.Value(), b.Value())).toFixed(4); }]);
 </script> 
/*
This example is licensed under a 
Creative Commons Attribution ShareAlike 4.0 International License.
https://creativecommons.org/licenses/by-sa/4.0/

Please note you have to mention 
The Center of Mobile Learning with Digital Technology
in the credits.
*/

const BOARDID = 'your_div_id'; // Insert your id here!

var board = JXG.JSXGraph.initBoard(BOARDID, { axis: true, boundingbox: [-2, 40, 8, -5] });

var s = board.create('slider', [[1, 30], [6, 30], [3, 5, 50]], { name: 'n', snapWidth: 1 });
var a = board.create('slider', [[1, 25], [6, 25], [-10, 0, 0]], { name: 'start' });
var b = board.create('slider', [[1, 20], [6, 20], [0, 6, 10]], { name: 'end' });

var f = function(x) { return -x * (x - 6); };
var plot = board.create('functiongraph', [f, function() { return a.Value(); }, function() { return b.Value(); }]);

var os = board.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 });

board.create('text',
      [1, 35, function() { return 'approx. sum = ' + (JXG.Math.Numerics.riemannsum(f, s.Value(), document.getElementById('sumtype')
            .value, a.Value(), b.Value())).toFixed(4); }]);

Riemann sum III

Approximate the integral of $f: {\mathbb R}\to {\mathbb R}, x\mapsto -x(x-6) = -x^2+6x$ in the interval $[0,6]$. The exact result is: $$ \int_0^6 -x^2+6x\,dx = 36\,. $$
Riemann sum type:
Riemann sum type: <select id="sumtype" onChange="board.update()">
    <option value='lower' selected> lower
    <option value='upper'> upper
    <option value='left'> left
    <option value='right'> right
    <option value='middle'> middle
    <option value='trapezoidal'> trapezoidal
    <option value='simpson'> simpson
</select>
// Define the id of your board in BOARDID

var board = JXG.JSXGraph.initBoard(BOARDID, { axis: true, boundingbox: [-2, 40, 8, -5] });

var s = board.create('slider', [[1, 30], [6, 30], [3, 5, 50]], { name: 'n', snapWidth: 1 });
var a = board.create('slider', [[1, 25], [6, 25], [-10, 0, 0]], { name: 'start' });
var b = board.create('slider', [[1, 20], [6, 20], [0, 6, 10]], { name: 'end' });

var f = function(x) { return -x * (x - 6); };
var plot = board.create('functiongraph', [f, function() { return a.Value(); }, function() { return b.Value(); }]);

var os = board.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 });

board.create('text',
      [1, 35, function() { return 'approx. sum = ' + (JXG.Math.Numerics.riemannsum(f, s.Value(), document.getElementById('sumtype')
            .value, a.Value(), b.Value())).toFixed(4); }]);

license

This example is licensed under a Creative Commons Attribution ShareAlike 4.0 International License.
Please note you have to mention The Center of Mobile Learning with Digital Technology in the credits.