Power series for the exponential function: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
<jsxgraph width="600" height="400" box="jxgbox1"> | <jsxgraph width="600" height="400" box="jxgbox1"> | ||
board1 = JXG.JSXGraph.initBoard('jxgbox1', {boundingbox: [-6, 25, 6, -15], axis: true}); | |||
board1 = JXG.JSXGraph.initBoard('jxgbox1', { | |||
board1.suspendUpdate(); | board1.suspendUpdate(); | ||
board1. | board1.create('functiongraph', | ||
[function(t){ return Math.exp(t); },-10, 10], | [function(t){ return Math.exp(t); },-10, 10], | ||
{strokeColor: "#cccccc"}); | {strokeColor: "#cccccc"}); | ||
var s = board1. | var s = board1.create('slider', [[0.75,-2],[5,-2.0],[0,0,15]], {name:'S',snapWidth:1}); | ||
board1. | board1.create('text',[-4,10, function() { | ||
return 'n='+s.Value(); | return 'n='+s.Value(); | ||
} | } | ||
]); | ]); | ||
board1. | board1.create('text',[-4,8, function() { | ||
var val = 0, i, sv = s.Value()+1; | var val = 0, i, sv = s.Value()+1; | ||
for(i = 0; i < sv; i++) { | for(i = 0; i < sv; i++) { | ||
val+= 1.0/ | val+= 1.0/JXG.Math.factorial(i); | ||
} | } | ||
return 'e~'+ | return 'e~'+(val).toFixed(10); | ||
} | } | ||
]); | ]); | ||
board1. | board1.create('functiongraph', [ | ||
function(t) { | function(t) { | ||
var val = 0, i, sv = s.Value()+1; | var val = 0, i, sv = s.Value()+1; | ||
for(i = 0; i < sv; i++) { | for(i = 0; i < sv; i++) { | ||
val+= Math.pow(t,i)/ | val+= Math.pow(t,i)/JXG.Math.factorial(i); | ||
} | } | ||
return val; | return val; | ||
Line 43: | Line 39: | ||
<source lang="javascript"> | <source lang="javascript"> | ||
board1 = JXG.JSXGraph.initBoard('jxgbox1', {boundingbox: [-6, 25, 6, -15], axis: true}); | |||
board1 = JXG.JSXGraph.initBoard('jxgbox1', { | |||
board1.suspendUpdate(); | board1.suspendUpdate(); | ||
board1. | board1.create('functiongraph', | ||
[function(t){ return Math.exp(t); },-10, 10], | |||
{strokeColor: "#cccccc"}); | |||
var s = board1.create('slider', [[0.75,-2],[5,-2.0],[0,0,15]], {name:'S',snapWidth:1}); | |||
board1.create('text',[-4,10, function() { | |||
var s = board1. | |||
board1. | |||
return 'n='+s.Value(); | return 'n='+s.Value(); | ||
}]); | } | ||
board1. | ]); | ||
board1.create('text',[-4,8, function() { | |||
var val = 0, i, sv = s.Value()+1; | var val = 0, i, sv = s.Value()+1; | ||
for(i = 0; i < sv; i++) { | for(i = 0; i < sv; i++) { | ||
val+= 1.0/ | val+= 1.0/JXG.Math.factorial(i); | ||
} | } | ||
return 'e~'+ | return 'e~'+(val).toFixed(10); | ||
}]); | } | ||
board1. | ]); | ||
board1.create('functiongraph', [ | |||
function(t) { | function(t) { | ||
var val = 0, i, sv = s.Value()+1; | var val = 0, i, sv = s.Value()+1; | ||
for(i = 0; i < sv; i++) { | for(i = 0; i < sv; i++) { | ||
val+= Math.pow(t,i)/ | val+= Math.pow(t,i)/JXG.Math.factorial(i); | ||
} | } | ||
return val; | return val; |
Latest revision as of 15:44, 20 February 2013
References
The underlying JavaScript code
board1 = JXG.JSXGraph.initBoard('jxgbox1', {boundingbox: [-6, 25, 6, -15], axis: true});
board1.suspendUpdate();
board1.create('functiongraph',
[function(t){ return Math.exp(t); },-10, 10],
{strokeColor: "#cccccc"});
var s = board1.create('slider', [[0.75,-2],[5,-2.0],[0,0,15]], {name:'S',snapWidth:1});
board1.create('text',[-4,10, function() {
return 'n='+s.Value();
}
]);
board1.create('text',[-4,8, function() {
var val = 0, i, sv = s.Value()+1;
for(i = 0; i < sv; i++) {
val+= 1.0/JXG.Math.factorial(i);
}
return 'e~'+(val).toFixed(10);
}
]);
board1.create('functiongraph', [
function(t) {
var val = 0, i, sv = s.Value()+1;
for(i = 0; i < sv; i++) {
val+= Math.pow(t,i)/JXG.Math.factorial(i);
}
return val;
},
-10, 10], {strokeColor: "#bb0000", curveType:'plot'});
board1.unsuspendUpdate();