Difference between revisions of "Power Series for sine and cosine"

From JSXGraph Wiki
Jump to: navigation, search
 
(43 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<html>
+
== Power Series for Sine ==
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
+
:<math>\sum_{k=0}^n (-1)^k\frac{1}{(2k+1)!}x^{2k+1}</math>
<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>
+
<jsxgraph box="jxgbox1" width="700" height="300">
<div id="jxgbox1" class="jxgbox" style="width:600px; height:300px;"></div>
+
board1 = JXG.JSXGraph.initBoard('jxgbox1', {axis:true, boundingbox: [-6, 3, 8, -3]});
<script language="JavaScript">
 
// Board
 
board1 = JXG.JSXGraph.initBoard('jxgbox1', {originX: 300, originY: 100, unitX: 50, unitY: 50});
 
 
board1.suspendUpdate();
 
board1.suspendUpdate();
// Axes and Properties
+
board1.create('functiongraph', [function(t){ return Math.sin(t); },-10, 10],{strokeColor: "#cccccc"});
board1.createElement('axis', [[1,0], [0,0]], {});
+
var s = board1.create('slider', [[0.75,-1.5],[5.75,-1.5],[0,0,10]], {name:'S',snapWidth:1});
board1.createElement('axis', [[0,1], [0,0]], {});
+
board1.create('functiongraph', [
board1.snapToGrid = true;
 
//
 
board1.createElement('curve', [function(t){ return t; }, function(t){ return Math.sin(t); }, "t", -10, 10],{strokeColor: "#cccccc"});
 
//
 
var s = board1.createElement('slider', [2,-4,5,0,10,0], {name:'S'});
 
//
 
board1.createElement('curve', [
 
function(t){ return t; },
 
 
function(t) {
 
function(t) {
var val = 0;
+
var val = 0, i, sv = s.Value()+1;
for(var i = 0; i < Math.floor(s.X()) + 1; i++) {
+
for(i = 0; i < sv; i++) {
var f = 1;
+
   val = val + Math.pow(-1, i) * Math.pow(t, 2 * i + 1) / JXG.Math.factorial(2*i+1);
var n = 1;
 
while (n <= 2 * i + 1) { f = f * n++; }
 
   val = val + Math.pow(-1, i) * Math.pow(t, 2 * i + 1) / f;
 
 
}
 
}
 
return val;
 
return val;
 
},
 
},
"t", -10, 10], {strokeColor: "#bb0000"});
+
-10, 10], {strokeColor: "#bb0000"});
 
board1.unsuspendUpdate();
 
board1.unsuspendUpdate();
/*
+
</jsxgraph>
*/
+
 
</script>  
+
<source lang="javascript">
<h2>Power Series for Cosine</h2>
+
board1 = JXG.JSXGraph.initBoard('jxgbox1', {axis:true, boundingbox: [-6, 3, 8, -3]});
<div id="jxgbox2" class="jxgbox" style="width:600px; height:300px;"></div>
+
board1.suspendUpdate();
<script language="JavaScript">
+
board1.create('functiongraph', [function(t){ return Math.sin(t); },-10, 10],{strokeColor: "#cccccc"});
// Board
+
var s = board1.create('slider', [[0.75,-1.5],[5.75,-1.5],[0,0,10]], {name:'S',snapWidth:1});
board2 = JXG.JSXGraph.initBoard('jxgbox2', {originX: 300, originY: 150, unitX: 25, unitY: 25});
+
board1.create('functiongraph', [
 +
  function(t) {
 +
    var val = 0, i, sv = s.Value()+1;
 +
    for(i = 0; i < sv; i++) {
 +
      val = val + Math.pow(-1, i) * Math.pow(t, 2 * i + 1) / JXG.Math.factorial(2*i+1);
 +
    }
 +
    return val;
 +
  }, -10, 10], {strokeColor: "#bb0000"});
 +
board1.unsuspendUpdate();
 +
</source>
 +
 
 +
 
 +
== Power Series for Cosine ==
 +
<jsxgraph box="jxgbox2" width="700" height="300">
 +
board2 = JXG.JSXGraph.initBoard('jxgbox2', {axis:true, boundingbox: [-6, 3, 8, -3]});
 
board2.suspendUpdate();
 
board2.suspendUpdate();
// Axes and Properties
+
board2.create('functiongraph', [function(t){ return Math.cos(t); }, -10, 10],{strokeColor: "#cccccc"});
board2.createElement('axis', [[1,0], [0,0]], {});
+
var s2 = board2.create('slider', [[0.75,-1.5],[5.75,-1.5],[0,0,10]], {name:'T',snapWidth:1});
board2.createElement('axis', [[0,1], [0,0]], {});
+
board2.create('functiongraph', [
board2.snapToGrid = true;
 
//
 
board2.createElement('curve', [function(t){ return t; }, function(t){ return Math.cos(t); }, "t", -10, 10],{strokeColor: "#cccccc"});
 
//
 
var s2 = board2.createElement('slider', [2,-4,5,0,10,0], {name:'T'});
 
//
 
board2.createElement('curve', [
 
function(t){ return t; },
 
 
function(t) {
 
function(t) {
var val = 0;
+
var val = 0, i, sv = s2.Value()+1;
for(var i = 0; i < Math.floor(s2.X()) + 1; i++) {
+
for(i = 0; i < sv; i++) {
var f = 1;
+
   val = val + Math.pow(-1, i) * Math.pow(t, 2 * i) / JXG.Math.factorial(2*i);
var n = 1;
 
while (n <= 2 * i) { f = f * n++; }
 
   val = val + Math.pow(-1, i) * Math.pow(t, 2 * i) / f;
 
 
}
 
}
 
return val;
 
return val;
 
},
 
},
"t", -10, 10],{strokeColor: "#009900"});
+
-10, 10],{strokeColor: "#009900"});
 +
board2.unsuspendUpdate();
 +
</jsxgraph>
 +
 
 +
<source lang="javascript">
 +
board2 = JXG.JSXGraph.initBoard('jxgbox2', {axis:true, boundingbox: [-6, 3, 8, -3]});
 +
board2.suspendUpdate();
 +
board2.create('functiongraph', [function(t){ return Math.cos(t); }, -10, 10],{strokeColor: "#cccccc"});
 +
var s2 = board2.create('slider', [[0.75,-1.5],[5.75,-1.5],[0,0,10]], {name:'T',snapWidth:1});
 +
board2.create('functiongraph', [
 +
  function(t) {
 +
    var val = 0, i, sv = Math.floor(s2.Value())+1;
 +
    for(i = 0; i < sv; i++) {
 +
      val = val + Math.pow(-1, i) * Math.pow(t, 2 * i) / JXG.Math.factorial(2*i);
 +
    }
 +
    return val;
 +
  }, -10, 10],{strokeColor: "#009900"});
 
board2.unsuspendUpdate();
 
board2.unsuspendUpdate();
</script>
+
</source>
 +
 
 +
=== References ===
 +
* [http://en.wikipedia.org/wiki/Trigonometric_functions http://en.wikipedia.org/wiki/Trigonometric_functions]
 +
 
 +
[[Category:Examples]]
 +
[[Category:Calculus]]

Latest revision as of 16:42, 20 February 2013

Power Series for Sine

[math]\sum_{k=0}^n (-1)^k\frac{1}{(2k+1)!}x^{2k+1}[/math]

board1 = JXG.JSXGraph.initBoard('jxgbox1', {axis:true, boundingbox: [-6, 3, 8, -3]});
board1.suspendUpdate();
board1.create('functiongraph', [function(t){ return Math.sin(t); },-10, 10],{strokeColor: "#cccccc"});
var s = board1.create('slider', [[0.75,-1.5],[5.75,-1.5],[0,0,10]], {name:'S',snapWidth:1});
board1.create('functiongraph', [
  function(t) {
    var val = 0, i, sv = s.Value()+1;
    for(i = 0; i < sv; i++) {
      val = val + Math.pow(-1, i) * Math.pow(t, 2 * i + 1) / JXG.Math.factorial(2*i+1);
    }
    return val;
  }, -10, 10], {strokeColor: "#bb0000"});
board1.unsuspendUpdate();


Power Series for Cosine

board2 = JXG.JSXGraph.initBoard('jxgbox2', {axis:true, boundingbox: [-6, 3, 8, -3]});
board2.suspendUpdate();
board2.create('functiongraph', [function(t){ return Math.cos(t); }, -10, 10],{strokeColor: "#cccccc"});
var s2 = board2.create('slider', [[0.75,-1.5],[5.75,-1.5],[0,0,10]], {name:'T',snapWidth:1});
board2.create('functiongraph', [
  function(t) {
    var val = 0, i, sv = Math.floor(s2.Value())+1;
    for(i = 0; i < sv; i++) {
      val = val + Math.pow(-1, i) * Math.pow(t, 2 * i) / JXG.Math.factorial(2*i);
    }
    return val;
  }, -10, 10],{strokeColor: "#009900"});						
board2.unsuspendUpdate();

References