Convergence of sequence: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary  | 
				A WASSERMANN (talk | contribs) No edit summary  | 
				||
| (8 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
Compute values of the sequence    | Compute values of the sequence  | ||
<math> (a_n)_{n\in{\mathbb N}}</math>.  | <math> (a_n)_{n\in{\mathbb N}}</math>.  | ||
<html>  | <html>  | ||
<p>  | <p>  | ||
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">,   | ||
start at n = <input type="number" id="startval" value="1" style="width:2em"><br />  | |||
<input type="button" value="start" onClick="start_approx()">  | <input type="button" value="start" onClick="start_approx()">  | ||
<input type="button" value="stop" onClick="clear_all()">  | <input type="button" value="stop" onClick="clear_all()">  | ||
| Line 9: | Line 10: | ||
<jsxgraph width="500" height="500" box="box">  | <jsxgraph width="500" height="500" box="box">  | ||
  var board = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox: [-3, 8, 50, -8]});  |   var board = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox: [-3, 8, 50, -8]});  | ||
  var seq = board.create('curve', [[  |   var seq = board.create('curve', [[], []], {strokeColor: 'blue'});  | ||
  var n;  | |||
  var seq_add = function() {  |   var seq_add = function() {  | ||
     var   |      var val = a_n(n);  | ||
     seq.dataX.push(n);  |      seq.dataX.push(n);  | ||
     seq.dataY.push(val);  |      seq.dataY.push(val);  | ||
    n++;  | |||
  };  |   };  | ||
| Line 25: | Line 27: | ||
      seq_add();  |       seq_add();  | ||
      board.update();  |       board.update();  | ||
      if (  |       if (n <= 50) {  | ||
          TO = setTimeout(approx, 500);  |           TO = setTimeout(approx, 500);  | ||
      }  |       }  | ||
| Line 34: | Line 36: | ||
   var txtraw = document.getElementById('input').value;  |    var txtraw = document.getElementById('input').value;  | ||
   a_n = board.jc.snippet(txtraw, true, 'n', true);  |    a_n = board.jc.snippet(txtraw, true, 'n', true);  | ||
  seq.dataX = [];  | |||
  seq.dataY = [];  | |||
  n = parseInt(document.getElementById('startval').value);  | |||
   approx();  |    approx();  | ||
}  | }  | ||
| Line 39: | Line 44: | ||
var clear_all = function() {  | var clear_all = function() {  | ||
   clearTimeout(TO);  |    clearTimeout(TO);  | ||
};  | };  | ||
| Line 48: | Line 51: | ||
<source lang="javascript">  | <source lang="javascript">  | ||
  var board = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox: [-3, 8, 50, -8]});  |   var board = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox: [-3, 8, 50, -8]});  | ||
  var seq = board.create('curve', [[  |   var seq = board.create('curve', [[], []], {strokeColor: 'blue'});  | ||
  var n;  | |||
  var seq_add = function() {  |   var seq_add = function() {  | ||
     var   |      var val = a_n(n);  | ||
     seq.dataX.push(n);  |      seq.dataX.push(n);  | ||
     seq.dataY.push(val);  |      seq.dataY.push(val);  | ||
    n++;  | |||
  };  |   };  | ||
| Line 64: | Line 68: | ||
      seq_add();  |       seq_add();  | ||
      board.update();  |       board.update();  | ||
      if (  |       if (n <= 50) {  | ||
          TO = setTimeout(approx, 500);  |           TO = setTimeout(approx, 500);  | ||
      }  |       }  | ||
| Line 73: | Line 77: | ||
   var txtraw = document.getElementById('input').value;  |    var txtraw = document.getElementById('input').value;  | ||
   a_n = board.jc.snippet(txtraw, true, 'n', true);  |    a_n = board.jc.snippet(txtraw, true, 'n', true);  | ||
  seq.dataX = [];  | |||
  seq.dataY = [];  | |||
  n = parseInt(document.getElementById('startval').value);  | |||
   approx();  |    approx();  | ||
}  | }  | ||
| Line 78: | Line 85: | ||
var clear_all = function() {  | var clear_all = function() {  | ||
   clearTimeout(TO);  |    clearTimeout(TO);  | ||
};  | };  | ||
</source>  | </source>  | ||
[[Category:Examples]]  | [[Category:Examples]]  | ||
[[Category:Calculus]]  | [[Category:Calculus]]  | ||
Latest revision as of 09:38, 30 January 2019
Compute values of the sequence [math]\displaystyle{ (a_n)_{n\in{\mathbb N}} }[/math].
nth-element of the sequence: , 
start at n = 
The underlying JavaScript code
 var board = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox: [-3, 8, 50, -8]});
 var seq = board.create('curve', [[], []], {strokeColor: 'blue'});
 var 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, 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 (n <= 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);
  seq.dataX = [];
  seq.dataY = [];
  n = parseInt(document.getElementById('startval').value);
  approx();
}
var clear_all = function() {
  clearTimeout(TO);
};