JSXGraph logo
JSXGraph
JSXGraph share

Share

Riemann sums
QR code
<iframe 
    src="https://jsxgraph.org/share/iframe/riemann-sums" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: Riemann sums" 
    allowfullscreen
></iframe>
This code has to
Riemann sum type: <select id="sumtype" onChange="board.update();">
    <option value='lower'> lower
    <option value='upper'> upper
    <option value='left' selected> 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: [-8, 4, 8, -4] });
    
    var s = board.create('slider', [[1, 3], [5, 3], [1, 10, 50]], { name: 'n', snapWidth: 1 });
    var a = board.create('slider', [[1, 2.5], [5, 2.5], [-10, -2 * Math.PI, 0]], { name: 'start' });
    var b = board.create('slider', [[1, 2], [5, 2], [0, Math.PI, 10]], { name: 'end' });
    
    var f = (x) => Math.sin(x);
    var plot = board.create('functiongraph', [f, () => a.Value(), () => b.Value()]);
    
    var os = board.create('riemannsum', [f,
        () => s.Value(),
        () => document.getElementById('sumtype').value,
        () => a.Value(),
        () => b.Value()
    ], { fillColor: '#ffff00', fillOpacity: 0.3 });
    
    board.create('text', [-6, -3, 
        () => 'Riemann 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: [-8, 4, 8, -4] });

var s = board.create('slider', [[1, 3], [5, 3], [1, 10, 50]], { name: 'n', snapWidth: 1 });
var a = board.create('slider', [[1, 2.5], [5, 2.5], [-10, -2 * Math.PI, 0]], { name: 'start' });
var b = board.create('slider', [[1, 2], [5, 2], [0, Math.PI, 10]], { name: 'end' });

var f = (x) => Math.sin(x);
var plot = board.create('functiongraph', [f, () => a.Value(), () => b.Value()]);

var os = board.create('riemannsum', [f,
    () => s.Value(),
    () => document.getElementById('sumtype').value,
    () => a.Value(),
    () => b.Value()
], { fillColor: '#ffff00', fillOpacity: 0.3 });

board.create('text', [-6, -3, 
    () => 'Riemann sum = ' + (JXG.Math.Numerics.riemannsum(f, s.Value(), document.getElementById('sumtype').value, a.Value(), b.Value())).toFixed(4)
]);

Riemann sums

Approximate the integral of the sine function over a configurable interval controlled by sliders for the start and end points. A Riemann sum with a selectable number of subdivisions and sum type is drawn under the curve, and its computed value is displayed dynamically. For the given interval the exact value is $$ \int_{-2\pi}^\pi \sin(x)\, dx = 2\;. $$
Riemann sum type:
Riemann sum type: <select id="sumtype" onChange="board.update();">
    <option value='lower'> lower
    <option value='upper'> upper
    <option value='left' selected> 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: [-8, 4, 8, -4] });

var s = board.create('slider', [[1, 3], [5, 3], [1, 10, 50]], { name: 'n', snapWidth: 1 });
var a = board.create('slider', [[1, 2.5], [5, 2.5], [-10, -2 * Math.PI, 0]], { name: 'start' });
var b = board.create('slider', [[1, 2], [5, 2], [0, Math.PI, 10]], { name: 'end' });

var f = (x) => Math.sin(x);
var plot = board.create('functiongraph', [f, () => a.Value(), () => b.Value()]);

var os = board.create('riemannsum', [f,
    () => s.Value(),
    () => document.getElementById('sumtype').value,
    () => a.Value(),
    () => b.Value()
], { fillColor: '#ffff00', fillOpacity: 0.3 });

board.create('text', [-6, -3, 
    () => 'Riemann 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.