| 1 |
<html> |
| 2 |
<head> |
| 3 |
<title>JSXGraph example</title> |
| 4 |
<link rel="stylesheet" type="text/css" href="../distrib/jsxgraph.css" /> |
| 5 |
<script type="text/javascript" src="prototype.js"></script> |
| 6 |
<script type="text/javascript" src="../distrib/jsxgraphcore.js"></script> |
| 7 |
</head> |
| 8 |
<body> |
| 9 |
<h2>Power Series for Sine</h2> |
| 10 |
<div id="jxgbox1" class="jxgbox" style="width:600px; height:300px;"></div> |
| 11 |
<br clear=all> |
| 12 |
<div id="debug" style="display:block;"></div> |
| 13 |
<script language="JavaScript"> |
| 14 |
// Board |
| 15 |
board1 = JXG.JSXGraph.initBoard('jxgbox1', {originX: 200, originY: 150, unitX: 5, unitY: 5}); |
| 16 |
|
| 17 |
board1.suspendUpdate(); |
| 18 |
// Axes and Properties |
| 19 |
board1.createElement('axis', [[0,0], [1,0]], {}); |
| 20 |
board1.createElement('axis', [[0,0], [0,1]], {}); |
| 21 |
board1.snapToGrid = true; |
| 22 |
// |
| 23 |
board1.createElement('functiongraph', [function(t){ return Math.sin(t); }, -10, 10],{strokeColor: "#cccccc"}); |
| 24 |
var s = board1.createElement('slider', [[2,-4],[7,-4],[0,1,10]], {name:'S',snapWidth:1}); |
| 25 |
|
| 26 |
board1.createElement('curve', [ |
| 27 |
function(t){ return t; }, |
| 28 |
function(t) { |
| 29 |
var val = 0; |
| 30 |
for(var i = 0; i < s.Value() + 1; i++) { |
| 31 |
var f = JXG.Math.factorial(2*i+1); // sin |
| 32 |
val += Math.pow(-1, i) * Math.pow(t, 2 * i + 1) / f; |
| 33 |
} |
| 34 |
return val; |
| 35 |
}, |
| 36 |
-10, 10], {strokeColor: "#bb0000"}); |
| 37 |
board1.unsuspendUpdate(); |
| 38 |
</script> |
| 39 |
|
| 40 |
<h2>Power Series for Cosine</h2> |
| 41 |
<div id="jxgbox2" class="jxgbox" style="width:600px; height:300px;"></div> |
| 42 |
<script language="JavaScript"> |
| 43 |
// Board |
| 44 |
board2 = JXG.JSXGraph.initBoard('jxgbox2', {originX: 300, originY: 150, unitX: 25, unitY: 25}); |
| 45 |
board2.suspendUpdate(); |
| 46 |
// Axes and Properties |
| 47 |
board2.createElement('axis', [[0,0], [1,0]], {}); |
| 48 |
board2.createElement('axis', [[0,0], [0,1]], {}); |
| 49 |
board2.snapToGrid = true; |
| 50 |
// |
| 51 |
board2.createElement('functiongraph', [function(t){ return Math.cos(t); }, -10, 10],{strokeColor: "#cccccc"}); |
| 52 |
var s2 = board2.createElement('slider', [[2,-4],[7,-4],[0,0,10]], {name:'S2',snapWidth:1}); |
| 53 |
|
| 54 |
board2.createElement('curve', [ |
| 55 |
function(t){ return t; }, |
| 56 |
function(t) { |
| 57 |
var val = 0; |
| 58 |
for(var i = 0; i < s2.Value() + 1; i++) { |
| 59 |
//var f = 1; |
| 60 |
//var n = 1; |
| 61 |
//while (n <= 2 * i) { f = f * n++; } |
| 62 |
var f = JXG.Math.factorial(2*i); |
| 63 |
val += Math.pow(-1, i) * Math.pow(t, 2 * i) / f; |
| 64 |
} |
| 65 |
return val; |
| 66 |
}, |
| 67 |
-10, 10],{strokeColor: "#009900"}); |
| 68 |
board2.unsuspendUpdate(); |
| 69 |
</script> |
| 70 |
|
| 71 |
<h2>Binomial theorem</h2> |
| 72 |
<div id="jxgbox3" class="jxgbox" style="width:600px; height:300px;"></div> |
| 73 |
<script language="JavaScript"> |
| 74 |
board3 = JXG.JSXGraph.initBoard('jxgbox3', {originX: 300, originY: 150, unitX: 25, unitY: 25, axis:true, grid:true}); |
| 75 |
board3.suspendUpdate(); |
| 76 |
board3.snapToGrid = true; |
| 77 |
// |
| 78 |
var s3 = board3.createElement('slider', [[2,-4],[7,-4],[0,0,10]], {name:'S3',snapWidth:1}); |
| 79 |
board3.createElement('functiongraph', [function(t){ return Math.pow(1+t,s3.Value()); }, -10, 10],{strokeColor: "#cccccc"}); |
| 80 |
|
| 81 |
board3.createElement('functiongraph', [ |
| 82 |
function(x) { |
| 83 |
var val = 0; |
| 84 |
var n = Math.round(s3.Value()); |
| 85 |
var z = 1; |
| 86 |
for(var k=0; k<=n; k++) { |
| 87 |
var f = JXG.Math.binomial(n,k); |
| 88 |
val += z*f; |
| 89 |
z *= x; |
| 90 |
} |
| 91 |
return val; |
| 92 |
}, |
| 93 |
-3, 3],{strokeColor: "#009900"}); |
| 94 |
board3.unsuspendUpdate(); |
| 95 |
</script> |
| 96 |
|
| 97 |
</body> |
| 98 |
</html> |