Difference between revisions of "Harmonic Waves"

From JSXGraph Wiki
Jump to: navigation, search
Line 38: Line 38:
 
</html>
 
</html>
  
 +
<source lang="javascript">
 +
    board1 = JXG.JSXGraph.initBoard('jxgbox1', {originX: 300, originY: 200, unitX: 50, unitY: 50});
 +
    board1.suspendUpdate();
 +
    board1.createElement('axis', [[0,0], [1,0]], {});
 +
    board1.createElement('axis', [[0,0], [0,1]], {});
 +
    var s = board1.createElement('slider', [0.75,-2.5,5,0,10,0], {name:'S'});
 +
    board1.createElement('curve', [
 +
        't',
 +
        function(t) {
 +
            var val = 0;
 +
            var k = 1;
 +
            for(var i = 0; i < Math.floor(s.X()) + 1; i++) {
 +
                val = val + Math.sin(2*Math.PI*k*t)/k;
 +
                k += 1;
 +
            }
 +
            return val+2;
 +
            }, "t", -10, 10], {strokeColor: "#bb0000", curveType:'plot'});
 +
   
 +
        board1.createElement('curve', [
 +
            't',
 +
            function(t) {
 +
                var val = 0;
 +
                var k = 1;
 +
                for(var i = 0; i < Math.floor(s.X()) + 1; i++) {
 +
                    val = val + Math.sin(2*Math.PI*(2*k-1)*t)/(2*k-1);
 +
                    k += 1;
 +
                }
 +
                return val-2;
 +
                }, "t", -10, 10], {strokeColor: "#cc5520", curveType:'plot'});
 +
 +
    board1.unsuspendUpdate();       
 +
</source>
  
 
[[Category:Examples]]
 
[[Category:Examples]]

Revision as of 17:59, 28 November 2008

    board1 = JXG.JSXGraph.initBoard('jxgbox1', {originX: 300, originY: 200, unitX: 50, unitY: 50});
    board1.suspendUpdate();
    board1.createElement('axis', [[0,0], [1,0]], {});
    board1.createElement('axis', [[0,0], [0,1]], {});
    var s = board1.createElement('slider', [0.75,-2.5,5,0,10,0], {name:'S'});
    board1.createElement('curve', [
        't', 
        function(t) {
            var val = 0;
            var k = 1;
            for(var i = 0; i < Math.floor(s.X()) + 1; i++) {
                val = val + Math.sin(2*Math.PI*k*t)/k;
                k += 1;
            }
            return val+2;
            }, "t", -10, 10], {strokeColor: "#bb0000", curveType:'plot'});
    
        board1.createElement('curve', [
            't', 
            function(t) {
                var val = 0;
                var k = 1;
                for(var i = 0; i < Math.floor(s.X()) + 1; i++) {
                    val = val + Math.sin(2*Math.PI*(2*k-1)*t)/(2*k-1);
                    k += 1;
                }
                return val-2;
                }, "t", -10, 10], {strokeColor: "#cc5520", curveType:'plot'});

    board1.unsuspendUpdate();