Power series for the exponential function: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 1: Line 1:
<jsxgraph width="600" height="400" box="jxgbox1">
<jsxgraph width="600" height="400" box="jxgbox1">
// Board
board1 = JXG.JSXGraph.initBoard('jxgbox1', {originX: 300, originY: 250, unitX: 50, unitY: 10});
board1 = JXG.JSXGraph.initBoard('jxgbox1', {originX: 300, originY: 250, unitX: 50, unitY: 10});
board1.suspendUpdate();
board1.suspendUpdate();
// Axes and Properties
board1.create('axis', [[0,0], [1,0]], {});
board1.createElement('axis', [[0,0], [1,0]], {});
board1.create('axis', [[0,0], [0,1]], {});
board1.createElement('axis', [[0,0], [0,1]], {});
 
//
board1.create('functiongraph',  
board1.createElement('functiongraph',  
     [function(t){ return Math.exp(t); },-10, 10],
     [function(t){ return Math.exp(t); },-10, 10],
     {strokeColor: "#cccccc"});
     {strokeColor: "#cccccc"});
//
 
var s = board1.createElement('slider', [[0.75,-2],[5,-2.0],[0,0,15]], {name:'S',snapWidth:1});
var s = board1.create('slider', [[0.75,-2],[5,-2.0],[0,0,15]], {name:'S',snapWidth:1});
board1.createElement('text',[-4,10, function() {
board1.create('text',[-4,10, function() {
return 'n='+s.Value();
return 'n='+s.Value();
}
}
     ]);
     ]);
board1.createElement('text',[-4,8, function() {
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++) {
Line 24: Line 22:
}
}
     ]);
     ]);
//
 
board1.createElement('functiongraph', [
board1.create('functiongraph', [
function(t) {
function(t) {
var val = 0, i, sv = s.Value()+1;
var val = 0, i, sv = s.Value()+1;
Line 43: Line 41:


<source lang="javascript">
<source lang="javascript">
// Board
board1 = JXG.JSXGraph.initBoard('jxgbox1', {originX: 300, originY: 250, unitX: 50, unitY: 10});
board1 = JXG.JSXGraph.initBoard('jxgbox1', {originX: 300, originY: 250, unitX: 50, unitY: 10});
board1.suspendUpdate();
board1.suspendUpdate();
// Axes and Properties
board1.create('axis', [[0,0], [1,0]], {});
board1.createElement('axis', [[0,0], [1,0]], {});
board1.create('axis', [[0,0], [0,1]], {});
board1.createElement('axis', [[0,0], [0,1]], {});
 
//
board1.create('functiongraph',  
board1.createElement('functiongraph',  
    [function(t){ return Math.exp(t); },-10, 10],
        [function(t){ return Math.exp(t); }, -10, 10],
    {strokeColor: "#cccccc"});
        {strokeColor: "#cccccc"});
 
var s = board1.createElement('slider', [[0.75,-2],[5,-2.0],[0,0,15]], {name:'S',snapWidth:1});
var s = board1.create('slider', [[0.75,-2],[5,-2.0],[0,0,15]], {name:'S',snapWidth:1});
board1.createElement('text',[-4,10, function() {
board1.create('text',[-4,10, function() {
return 'n='+s.Value();
return 'n='+s.Value();
}]);
}
board1.createElement('text',[-4,8, function() {
    ]);
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++) {
Line 63: Line 61:
}
}
return 'e~'+board1.round(val,10);
return 'e~'+board1.round(val,10);
}]);
}
board1.createElement('functiongraph', [
    ]);
 
board1.create('functiongraph', [
function(t) {
function(t) {
var val = 0, i, sv = s.Value()+1;
var val = 0, i, sv = s.Value()+1;

Revision as of 16:01, 25 March 2011

References

The underlying JavaScript code

board1 = JXG.JSXGraph.initBoard('jxgbox1', {originX: 300, originY: 250, unitX: 50, unitY: 10});
board1.suspendUpdate();
board1.create('axis', [[0,0], [1,0]], {});
board1.create('axis', [[0,0], [0,1]], {});

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/board1.factorial(i);
		}
		return 'e~'+board1.round(val,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)/board1.factorial(i);
		}
		return val;
	},
-10, 10], {strokeColor: "#bb0000", curveType:'plot'});
board1.unsuspendUpdate();