Share JSXGraph: example "Convergence of series"

JSXGraph
Share JSXGraph: example "Convergence of series"
This website is a beta version. The official release will be in **2023**.

Convergence of series

Have also a look at "Convergence of sequence".
Compute partial sums of the series $\sum_{n=0}^\infty a_n$.
nth-element of the series: Start summation at n =
nth-element of the series: <input type="text" id="input" value="1 / 2^n">
Start summation at n = <input type="number" id="startval" value="0" style="width:3em"><br />
<input type="button" value="start" onClick="start_approx()">
<input type="button" value="stop" onClick="clear_all()">
// Define the id of your board in BOARDID

const board = JXG.JSXGraph.initBoard(BOARDID, {axis:true, boundingbox: [-3, 8, 50, -8]});

var series = board.create('curve', [[], []], {strokeColor: 'black'});
var n, a_n;
 
var series_add = function() {
    var val = a_n(n);
    if (series.dataY.length > 0) {
        val += series.dataY[series.dataY.length - 1];
    }
    series.dataX.push(n);
    series.dataY.push(val);
    n++;
};

var txt = board.create('text', [15, 1.8, () => 'n=' + (series.dataX.length-1) + ': value = ' + series.dataY[series.dataY.length - 1]], {strokeColor: 'blue'});

var timeoutHandle;

// Animation
var approx = function() {
     series_add();
     board.update();
     if (series.dataX.length <= 50) {
         timeoutHandle = setTimeout(approx, 500);
     }
};

// Start animation
var start_approx = function() {
    series.dataX = [];
    series.dataY = [];

    var txtraw = document.getElementById('input').value;
    a_n = board.jc.snippet(txtraw, true, 'n', true);
    n = parseInt(document.getElementById('startval').value);
    approx();
};

// Stop animation
var clear_all = function() {
    clearTimeout(timeoutHandle);
};