Convergence of series: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
(3 intermediate revisions by the same user not shown) | |||
Line 4: | Line 4: | ||
<p> | <p> | ||
nth-element of the series: <input type="text" id="input" value="1 / 2^n"> | nth-element of the series: <input type="text" id="input" value="1 / 2^n"> | ||
start summation at n = <input type="number" id="startval" value="0" 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 series = board.create('curve', [[ | var series = board.create('curve', [[], []], {strokeColor: 'black'}); | ||
var n; | |||
var series_add = function() { | var series_add = function() { | ||
var n | var val = a_n(n); | ||
if (series.dataY.length > 0) { | |||
val += series.dataY[series.dataY.length - 1]; | |||
} | |||
series.dataX.push(n); | series.dataX.push(n); | ||
series.dataY.push(val); | series.dataY.push(val); | ||
n++; | |||
}; | }; | ||
Line 32: | Line 37: | ||
var a_n; | var a_n; | ||
var start_approx = function() { | var start_approx = function() { | ||
series.dataX = []; | |||
series.dataY = []; | |||
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); | ||
n = parseInt(document.getElementById('startval').value); | |||
approx(); | approx(); | ||
} | } | ||
Line 39: | Line 48: | ||
var clear_all = function() { | var clear_all = function() { | ||
clearTimeout(TO); | clearTimeout(TO); | ||
}; | }; | ||
Line 48: | Line 55: | ||
<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 series = board.create('curve', [[ | var series = board.create('curve', [[], []], {strokeColor: 'black'}); | ||
var n; | |||
var series_add = function() { | var series_add = function() { | ||
var n | var val = a_n(n); | ||
if (series.dataY.length > 0) { | |||
val += series.dataY[series.dataY.length - 1]; | |||
} | |||
series.dataX.push(n); | series.dataX.push(n); | ||
series.dataY.push(val); | series.dataY.push(val); | ||
n++; | |||
}; | }; | ||
Line 71: | Line 82: | ||
var a_n; | var a_n; | ||
var start_approx = function() { | var start_approx = function() { | ||
series.dataX = []; | |||
series.dataY = []; | |||
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); | ||
n = parseInt(document.getElementById('startval').value); | |||
approx(); | approx(); | ||
} | } | ||
Line 78: | Line 93: | ||
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:36, 30 January 2019
Compute partial sums of the series [math]\displaystyle{ \sum_{n=0}^\infty a_n }[/math].
nth-element of the series:
start summation at n =
The underlying JavaScript code
var board = JXG.JSXGraph.initBoard('box', {axis:true, boundingbox: [-3, 8, 50, -8]});
var series = board.create('curve', [[], []], {strokeColor: 'black'});
var n;
var series_add = function() {
var val = a_n(n);
if (series.dataY.length > 0) {
val += series.dataY[series.dataY.length - 1];
}
series.dataX.push(n);
series.dataY.push(val);
n++;
};
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() {
series.dataX = [];
series.dataY = [];
var txtraw = document.getElementById('input').value;
a_n = board.jc.snippet(txtraw, true, 'n', true);
n = parseInt(document.getElementById('startval').value);
approx();
}
var clear_all = function() {
clearTimeout(TO);
};