Share JSXGraph: example "Convergence of sequence"

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

Convergence of sequence

Have also a look at "Convergence of series".
Compute values of the sequence $(a_n)_{n\in{\mathbb N}}.
nth-element of the sequence: Start at n =
nth-element of the sequence: <input type="text" id="input" value="1 / n">
Start at n = <input type="number" id="startval" value="1" style="width:4em"><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 seq = board.create('curve', [[], []], {strokeColor: 'blue'});
var n, a_n;

 var seq_add = function() {
    var val = a_n(n);
    seq.dataX.push(n);
    seq.dataY.push(val);
    n++;
 };

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

var timeoutHandle;

// Approximation animation
var approx = function() {
     seq_add();
     board.update();
     if (n <= 50) {
         timeoutHandle = setTimeout(approx, 500);
     }
};

// Start new approximation
var start_approx = function() {
    // JessieCode function from user input
    var txtraw = document.getElementById('input').value;
    a_n = board.jc.snippet(txtraw, true, 'n', true);

    seq.dataX = [];
    seq.dataY = [];
    n = parseInt(document.getElementById('startval').value);
    approx();
}

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