Power series for the exponential function: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 3: Line 3:
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<div id="jxgbox1" class="jxgbox" style="width:600px; height:300px;"></div>
<div id="jxgbox1" class="jxgbox" style="width:600px; height:400px;"></div>
<script language="JavaScript">
<script language="JavaScript">
// Board
// Board
Line 16: Line 16:
     {strokeColor: "#cccccc"});
     {strokeColor: "#cccccc"});
//
//
var s = board1.createElement('slider', [[0.75,-2],[5,-2.0],[0,0,15]], {name:'S'});
var s = board1.createElement('slider', [[0.75,-2],[5,-2.0],[0,0,15]], {name:'S',snapWidth:1});
board1.createElement('text',[-4,10, function() {
board1.createElement('text',[-4,10, function() {
return 'n='+Math.floor(s.Value());
return 'n='+s.Value();
}
}
     ]);
     ]);
board1.createElement('text',[-4,8, function() {
board1.createElement('text',[-4,8, function() {
var val = 0;
var val = 0;
for(var i=0;i<= Math.floor(s.Value()); i++) {
for(var i=0;i<= s.Value(); i++) {
   val+= 1.0/board1.factorial(i);
   val+= 1.0/board1.factorial(i);
}
}
Line 33: Line 33:
function(t) {
function(t) {
var val = 0;
var val = 0;
for(var i=0;i<= Math.floor(s.Value()); i++) {
for(var i=0;i<= s.Value(); i++) {
   val+= Math.pow(t,i)/board1.factorial(i);
   val+= Math.pow(t,i)/board1.factorial(i);
}
}
Line 52: Line 52:
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<div id="jxgbox1" class="jxgbox" style="width:600px; height:300px;"></div>
<div id="jxgbox1" class="jxgbox" style="width:600px; height:400px;"></div>
</source>
</source>


Line 66: Line 66:
         [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'});
var s = board1.createElement('slider', [[0.75,-2],[5,-2.0],[0,0,15]], {name:'S',snapWidth:1});
board1.createElement('text',[-4,10, function() {
board1.createElement('text',[-4,10, function() {
return 'n='+Math.floor(s.Value());
return 'n='+s.Value();
}]);
}]);
board1.createElement('text',[-4,8, function() {
board1.createElement('text',[-4,8, function() {
var val = 0;
var val = 0;
for(var i=0;i<= Math.floor(s.Value()); i++) {
for(var i=0;i<= s.Value(); i++) {
   val+= 1.0/board1.factorial(i);
   val+= 1.0/board1.factorial(i);
}
}
Line 80: Line 80:
function(t) {
function(t) {
var val = 0;
var val = 0;
for(var i=0;i<= Math.floor(s.Value()); i++) {
for(var i=0;i<= s.Value(); i++) {
   val+= Math.pow(t,i)/board1.factorial(i);
   val+= Math.pow(t,i)/board1.factorial(i);
}
}

Revision as of 17:06, 22 June 2009

References

The underlying JavaScript code

<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<div id="jxgbox1" class="jxgbox" style="width:600px; height:400px;"></div>
// Board
board1 = JXG.JSXGraph.initBoard('jxgbox1', {originX: 300, originY: 250, unitX: 50, unitY: 10});
board1.suspendUpdate();
// Axes and Properties
board1.createElement('axis', [[0,0], [1,0]], {});
board1.createElement('axis', [[0,0], [0,1]], {});
//
board1.createElement('functiongraph', 
        [function(t){ return Math.exp(t); }, -10, 10],
        {strokeColor: "#cccccc"});
var s = board1.createElement('slider', [[0.75,-2],[5,-2.0],[0,0,15]], {name:'S',snapWidth:1});
board1.createElement('text',[-4,10, function() {
		return 'n='+s.Value();
	}]);
board1.createElement('text',[-4,8, function() {
		var val = 0;
		for(var i=0;i<= s.Value(); i++) {
   			val+= 1.0/board1.factorial(i);
		}
		return 'e~'+board1.round(val,10);
	}]);
board1.createElement('functiongraph', [
	function(t) {
		var val = 0;
		for(var i=0;i<= s.Value(); i++) {
   			val+= Math.pow(t,i)/board1.factorial(i);
		}
		return val;
	},
-10, 10], {strokeColor: "#bb0000", curveType:'plot'});
board1.unsuspendUpdate();