Difference between revisions of "Convergence of sequence"

From JSXGraph Wiki
Jump to: navigation, search
Line 5: Line 5:
 
nth-element of the sequence: <input type="text" id="input" value="1 / n">
 
nth-element of the sequence: <input type="text" id="input" value="1 / n">
 
<input type="button" value="start" onClick="start_approx()">
 
<input type="button" value="start" onClick="start_approx()">
<input type="button" value="clear all" onClick="clear_all()">
+
<input type="button" value="stop" onClick="clear_all()">
 
</html>
 
</html>
 
<jsxgraph width="500" height="500" box="box">
 
<jsxgraph width="500" height="500" box="box">
Line 18: Line 18:
 
  };
 
  };
  
var txt1 = board.create('text', [15, 1.6, function() { return 'n=' + (seq.dataX.length-1) + ': value = ' + seq.dataY[seq.dataY.length - 1]; }], {strokeColor: 'blue'});
+
var txt1 = board.create('text', [15, 1.6, function() { return 'n=' + (seq.dataX.length-1) + ': value = ' + seq.dataY[seq.dataY.length - 1]; }], {strokeColor: 'blue'});
  
 
var TO;
 
var TO;
Line 44: Line 44:
  
 
</jsxgraph>
 
</jsxgraph>
 +
 +
===The underlying JavaScript code===
 +
<source lang="javascript">
 +
var board = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox: [-3, 8, 50, -8]});
 +
var seq = board.create('curve', [[0], [1]], {strokeColor: 'blue'});
 +
 +
var seq_add = function() {
 +
    var n = seq.dataX.length,
 +
        val = a_n(n);
 +
    seq.dataX.push(n);
 +
    seq.dataY.push(val);
 +
};
 +
 +
var txt1 = board.create('text', [15, 1.6, function() { return 'n=' + (seq.dataX.length-1) + ': value = ' + seq.dataY[seq.dataY.length - 1]; }], {strokeColor: 'blue'});
 +
 +
var TO;
 +
 +
var approx = function() {
 +
    seq_add();
 +
    board.update();
 +
    if (seq.dataX.length <= 50) {
 +
        TO = setTimeout(approx, 500);
 +
    }
 +
};
 +
 +
var a_n;
 +
var start_approx = function() {
 +
  var txtraw = document.getElementById('input').value;
 +
  a_n = board.jc.snippet(txtraw, true, 'n', true);
 +
  approx();
 +
}
 +
 +
var clear_all = function() {
 +
  clearTimeout(TO);
 +
  seq.dataX = [0];
 +
  seq.dataY = [1];
 +
};
 +
</source>
 +
 +
[[Category:Examples]]
 +
[[Category:Calculus]]

Revision as of 10:35, 7 January 2019

Compute values of

[math] (a_n)_{n\in{\mathbb N}}[/math].

nth-element of the sequence:

The underlying JavaScript code

 var board = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox: [-3, 8, 50, -8]});
 var seq = board.create('curve', [[0], [1]], {strokeColor: 'blue'});
 
 var seq_add = function() {
    var n = seq.dataX.length,
        val = a_n(n);
    seq.dataX.push(n);
    seq.dataY.push(val);
 };

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

var TO;

var approx = function() {
     seq_add();
     board.update();
     if (seq.dataX.length <= 50) {
         TO = setTimeout(approx, 500);
     }
};

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

var clear_all = function() {
  clearTimeout(TO);
  seq.dataX = [0];
  seq.dataY = [1];
};