JSXGraph logo
JSXGraph
JSXGraph share

Share

Power series for sine and cosine
QR code
<iframe 
    src="http://jsxgraph.uni-bayreuth.de/share/iframe/power-series-for-sine-and-cosine" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: Power series for sine and cosine" 
    allowfullscreen
></iframe>
This code has to
<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>
<div id="board-1-wrapper" class="jxgbox-wrapper " style="width: 100%; ">
   <div id="board-1" 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 BOARDID0 = 'board-0';
    const BOARDID1 = 'board-1';
    const BOARDID = BOARDID0;

    var board1 = JXG.JSXGraph.initBoard(BOARDID0, {
        axis: true,
        boundingbox: [-6, 3, 8, -3],
        keepaspectratio: true
    });
    
    board1.create('functiongraph', [(t) => Math.sin(t), -10, 10], { strokeColor: "#cccccc" });
    
    var s = board1.create('slider', [[0.75, -1.5], [5.75, -1.5], [0, 0, 10]], { name: 'S', snapWidth: 1 });
    board1.create('functiongraph', [
        function(t) {
            var val = 0,
                i,
                sv = s.Value() + 1;
    
            for (i = 0; i < sv; i++) {
                val = val + Math.pow(-1, i) * Math.pow(t, 2 * i + 1) / JXG.Math.factorial(2 * i + 1);
            }
            return val;
        },
        -10, 10], { strokeColor: "#bb0000" });
    
    var board2 = JXG.JSXGraph.initBoard(BOARDID1, {
        axis: true,
        boundingbox: [-6, 3, 8, -3],
        keepaspectratio: true
    });
    
    board2.create('functiongraph', [(t) => Math.cos(t), -10, 10], { strokeColor: "#cccccc" });
    
    var s2 = board2.create('slider', [[0.75, -1.5], [5.75, -1.5], [0, 0, 10]], { name: 'T', snapWidth: 1 });
    board2.create('functiongraph', [
        function(t) {
            var val = 0,
                i,
                sv = s2.Value() + 1;
    
            for (i = 0; i < sv; i++) {
                val = val + Math.pow(-1, i) * Math.pow(t, 2 * i) / JXG.Math.factorial(2 * i);
            }
            return val;
        },
        -10, 10], { strokeColor: "#009900" });
 </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 BOARDID0 = 'your_div_id_0'; // Insert your 1st board id here!
const BOARDID1 = 'your_div_id_1'; // Insert your 2nd board id here!

var board1 = JXG.JSXGraph.initBoard(BOARDID0, {
    axis: true,
    boundingbox: [-6, 3, 8, -3],
    keepaspectratio: true
});

board1.create('functiongraph', [(t) => Math.sin(t), -10, 10], { strokeColor: "#cccccc" });

var s = board1.create('slider', [[0.75, -1.5], [5.75, -1.5], [0, 0, 10]], { name: 'S', snapWidth: 1 });
board1.create('functiongraph', [
    function(t) {
        var val = 0,
            i,
            sv = s.Value() + 1;

        for (i = 0; i < sv; i++) {
            val = val + Math.pow(-1, i) * Math.pow(t, 2 * i + 1) / JXG.Math.factorial(2 * i + 1);
        }
        return val;
    },
    -10, 10], { strokeColor: "#bb0000" });

var board2 = JXG.JSXGraph.initBoard(BOARDID1, {
    axis: true,
    boundingbox: [-6, 3, 8, -3],
    keepaspectratio: true
});

board2.create('functiongraph', [(t) => Math.cos(t), -10, 10], { strokeColor: "#cccccc" });

var s2 = board2.create('slider', [[0.75, -1.5], [5.75, -1.5], [0, 0, 10]], { name: 'T', snapWidth: 1 });
board2.create('functiongraph', [
    function(t) {
        var val = 0,
            i,
            sv = s2.Value() + 1;

        for (i = 0; i < sv; i++) {
            val = val + Math.pow(-1, i) * Math.pow(t, 2 * i) / JXG.Math.factorial(2 * i);
        }
        return val;
    },
    -10, 10], { strokeColor: "#009900" });
<jsxgraph width="100%, 100%" aspect-ratio="1 / 1, 1 / 1" numberOfBoards="2" title="Power series for sine and cosine" description="This construction was copied from JSXGraph examples database: BTW HERE SHOULD BE A GENERATED LINKuseGlobalJS="false">
   /*
   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.
   */
   
   var board1 = JXG.JSXGraph.initBoard(BOARDID0, {
       axis: true,
       boundingbox: [-6, 3, 8, -3],
       keepaspectratio: true
   });
   
   board1.create('functiongraph', [(t) => Math.sin(t), -10, 10], { strokeColor: "#cccccc" });
   
   var s = board1.create('slider', [[0.75, -1.5], [5.75, -1.5], [0, 0, 10]], { name: 'S', snapWidth: 1 });
   board1.create('functiongraph', [
       function(t) {
           var val = 0,
               i,
               sv = s.Value() + 1;
   
           for (i = 0; i < sv; i++) {
               val = val + Math.pow(-1, i) * Math.pow(t, 2 * i + 1) / JXG.Math.factorial(2 * i + 1);
           }
           return val;
       },
       -10, 10], { strokeColor: "#bb0000" });
   
   var board2 = JXG.JSXGraph.initBoard(BOARDID1, {
       axis: true,
       boundingbox: [-6, 3, 8, -3],
       keepaspectratio: true
   });
   
   board2.create('functiongraph', [(t) => Math.cos(t), -10, 10], { strokeColor: "#cccccc" });
   
   var s2 = board2.create('slider', [[0.75, -1.5], [5.75, -1.5], [0, 0, 10]], { name: 'T', snapWidth: 1 });
   board2.create('functiongraph', [
       function(t) {
           var val = 0,
               i,
               sv = s2.Value() + 1;
   
           for (i = 0; i < sv; i++) {
               val = val + Math.pow(-1, i) * Math.pow(t, 2 * i) / JXG.Math.factorial(2 * i);
           }
           return val;
       },
       -10, 10], { strokeColor: "#009900" });
</jsxgraph>

Power series for sine and cosine

This example demonstrates the Taylor series expansions of the sine and cosine functions expanded at $0$. The first graph shows $\sin(x)$ along with its polynomial approximation, based on the formula $$\sum_{k=0}^n (-1)^k\frac{1}{(2k+1)!}x^{2k+1}.$$ The slider controls the number of terms $n$. The second graph shows $\cos(x)$ and its approximation with an adjustable slider as well.
// Define the ids of your boards in BOARDID0, BOARDID1,...

var board1 = JXG.JSXGraph.initBoard(BOARDID0, {
    axis: true,
    boundingbox: [-6, 3, 8, -3],
    keepaspectratio: true
});

board1.create('functiongraph', [(t) => Math.sin(t), -10, 10], { strokeColor: "#cccccc" });

var s = board1.create('slider', [[0.75, -1.5], [5.75, -1.5], [0, 0, 10]], { name: 'S', snapWidth: 1 });
board1.create('functiongraph', [
    function(t) {
        var val = 0,
            i,
            sv = s.Value() + 1;

        for (i = 0; i < sv; i++) {
            val = val + Math.pow(-1, i) * Math.pow(t, 2 * i + 1) / JXG.Math.factorial(2 * i + 1);
        }
        return val;
    },
    -10, 10], { strokeColor: "#bb0000" });

var board2 = JXG.JSXGraph.initBoard(BOARDID1, {
    axis: true,
    boundingbox: [-6, 3, 8, -3],
    keepaspectratio: true
});

board2.create('functiongraph', [(t) => Math.cos(t), -10, 10], { strokeColor: "#cccccc" });

var s2 = board2.create('slider', [[0.75, -1.5], [5.75, -1.5], [0, 0, 10]], { name: 'T', snapWidth: 1 });
board2.create('functiongraph', [
    function(t) {
        var val = 0,
            i,
            sv = s2.Value() + 1;

        for (i = 0; i < sv; i++) {
            val = val + Math.pow(-1, i) * Math.pow(t, 2 * i) / JXG.Math.factorial(2 * i);
        }
        return val;
    },
    -10, 10], { strokeColor: "#009900" });

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.