Share JSXGraph: example "Waveforms: pulse and sawtooth"

JSXGraph
Share JSXGraph: example "Waveforms: pulse and sawtooth"
This website is a beta version. The official release will be in **2024**.

Waveforms: pulse and sawtooth

Approximation of the following waveforms: Reverse sawtooth wave: $$ 2 + \sum_{k=1}^\infty (-1)^k\frac{\sin(2\pi k t)}{k} $$ Pulse wave: $$ (-2) + \sum_{k=1}^\infty \frac{\sin(2 \pi (2k-1)k t)}{(2k-1)} $$
// Define the id of your board in BOARDID

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

var s = board.create('slider', [[0.75, -2], [4.5, -2], [0, 0, 10]], {name: 'S', snapWidth: 1});

board.create('functiongraph', [
    function(t) {
        var val = 0, sv = s.Value() + 1,  k;

        for (k = 1; k <= sv; k++) {
            val += Math.pow(-1, k) * Math.sin(2 * Math.PI * k * t) / k;
        }
        return val + 2;
    }, -10, 10
], {strokeColor: '#bb0000'});

board.create('functiongraph', [
    function(t) {
        var val = 0, sv = s.Value() + 1, k;

        for (k = 1; k <= sv; k++) {
            val += Math.sin(2 * Math.PI * (2 * k - 1) * t) / (2 * k - 1);
        }
        return val - 2;
    }, -10, 10
], {strokeColor: '#cc5520'});