Difference between revisions of "Convergence of series"
From JSXGraph Wiki
Jump to navigationJump to searchA WASSERMANN (talk | contribs) |
A WASSERMANN (talk | contribs) |
||
Line 3: | Line 3: | ||
<html> | <html> | ||
<p> | <p> | ||
− | nth-element of the series: <input type="text" id="input" value="1 / n"> | + | nth-element of the series: <input type="text" id="input" value="1 / 2^n"> |
<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 47: | Line 47: | ||
===The underlying JavaScript code=== | ===The underlying JavaScript code=== | ||
<source lang="javascript"> | <source lang="javascript"> | ||
+ | var board = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox: [-3, 8, 50, -8]}); | ||
+ | var series = board.create('curve', [[0], [1]], {strokeColor: 'black'}); | ||
+ | |||
+ | var series_add = function() { | ||
+ | var n = series.dataX.length, | ||
+ | val = series.dataY[n - 1] + a_n(n); | ||
+ | series.dataX.push(n); | ||
+ | series.dataY.push(val); | ||
+ | }; | ||
+ | |||
+ | var txt2 = board.create('text', [15, 1.8, function() { return 'n=' + (series.dataX.length-1) + ': value = ' + series.dataY[series.dataY.length - 1]; }], {strokeColor: 'black'}); | ||
+ | |||
+ | var TO; | ||
+ | |||
+ | var approx = function() { | ||
+ | series_add(); | ||
+ | board.update(); | ||
+ | if (series.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); | ||
+ | series.dataX = [0]; | ||
+ | series.dataY = [1]; | ||
+ | }; | ||
</source> | </source> | ||
[[Category:Examples]] | [[Category:Examples]] | ||
[[Category:Calculus]] | [[Category:Calculus]] |
Revision as of 10:44, 7 January 2019
Compute partial sums of the series [math] \sum_{n=0}^\infty a_n[/math].
nth-element of the series:
The underlying JavaScript code
var board = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox: [-3, 8, 50, -8]});
var series = board.create('curve', [[0], [1]], {strokeColor: 'black'});
var series_add = function() {
var n = series.dataX.length,
val = series.dataY[n - 1] + a_n(n);
series.dataX.push(n);
series.dataY.push(val);
};
var txt2 = board.create('text', [15, 1.8, function() { return 'n=' + (series.dataX.length-1) + ': value = ' + series.dataY[series.dataY.length - 1]; }], {strokeColor: 'black'});
var TO;
var approx = function() {
series_add();
board.update();
if (series.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);
series.dataX = [0];
series.dataY = [1];
};