Power Series for sine and cosine: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 5: Line 5:
board1 = JXG.JSXGraph.initBoard('jxgbox1', {axis:true, boundingbox: [-6, 3, 8, -3]});
board1 = JXG.JSXGraph.initBoard('jxgbox1', {axis:true, boundingbox: [-6, 3, 8, -3]});
board1.suspendUpdate();
board1.suspendUpdate();
board1.createElement('functiongraph', [function(t){ return Math.sin(t); },-10, 10],{strokeColor: "#cccccc"});
board1.create('functiongraph', [function(t){ return Math.sin(t); },-10, 10],{strokeColor: "#cccccc"});
var s = board1.createElement('slider', [[0.75,-1.5],[5.75,-1.5],[0,0,10]], {name:'S',snapWidth:1});
var s = board1.create('slider', [[0.75,-1.5],[5.75,-1.5],[0,0,10]], {name:'S',snapWidth:1});
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 22: Line 22:
board1 = JXG.JSXGraph.initBoard('jxgbox1', {axis:true, boundingbox: [-6, 3, 8, -3]});
board1 = JXG.JSXGraph.initBoard('jxgbox1', {axis:true, boundingbox: [-6, 3, 8, -3]});
board1.suspendUpdate();
board1.suspendUpdate();
board1.createElement('functiongraph', [function(t){ return Math.sin(t); },-10, 10],{strokeColor: "#cccccc"});
board1.create('functiongraph', [function(t){ return Math.sin(t); },-10, 10],{strokeColor: "#cccccc"});
var s = board1.createElement('slider', [[0.75,-1.5],[5.75,-1.5],[0,0,10]], {name:'S',snapWidth:1});
var s = board1.create('slider', [[0.75,-1.5],[5.75,-1.5],[0,0,10]], {name:'S',snapWidth:1});
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 37: Line 37:


== Power Series for Cosine ==
== Power Series for Cosine ==
<jsxgraph box="jxgbox1" width="700" height="300">
<jsxgraph box="jxgbox2" width="700" height="300">
board2 = JXG.JSXGraph.initBoard('jxgbox2', {axis:true, boundingbox: [-6, 3, 8, -3]});
board2 = JXG.JSXGraph.initBoard('jxgbox2', {axis:true, boundingbox: [-6, 3, 8, -3]});
board2.suspendUpdate();
board2.suspendUpdate();
board2.createElement('functiongraph', [function(t){ return Math.cos(t); }, -10, 10],{strokeColor: "#cccccc"});
board2.create('functiongraph', [function(t){ return Math.cos(t); }, -10, 10],{strokeColor: "#cccccc"});
var s2 = board2.createElement('slider', [[0.75,-1.5],[5.75,-1.5],[0,0,10]], {name:'T',snapWidth:1});
var s2 = board2.create('slider', [[0.75,-1.5],[5.75,-1.5],[0,0,10]], {name:'T',snapWidth:1});
board2.createElement('functiongraph', [
board2.create('functiongraph', [
function(t) {
function(t) {
var val = 0, i, sv = s2.Value()+1;
var val = 0, i, sv = s2.Value()+1;
Line 57: Line 57:
board2 = JXG.JSXGraph.initBoard('jxgbox2', {axis:true, boundingbox: [-6, 3, 8, -3]});
board2 = JXG.JSXGraph.initBoard('jxgbox2', {axis:true, boundingbox: [-6, 3, 8, -3]});
board2.suspendUpdate();
board2.suspendUpdate();
board2.createElement('functiongraph', [function(t){ return Math.cos(t); }, -10, 10],{strokeColor: "#cccccc"});
board2.create('functiongraph', [function(t){ return Math.cos(t); }, -10, 10],{strokeColor: "#cccccc"});
var s2 = board2.createElement('slider', [[0.75,-1.5],[5.75,-1.5],[0,0,10]], {name:'T',snapWidth:1});
var s2 = board2.create('slider', [[0.75,-1.5],[5.75,-1.5],[0,0,10]], {name:'T',snapWidth:1});
board2.createElement('functiongraph', [
board2.create('functiongraph', [
   function(t) {
   function(t) {
     var val = 0, i, sv = Math.floor(s2.Value())+1;
     var val = 0, i, sv = Math.floor(s2.Value())+1;

Revision as of 11:53, 8 June 2011

Power Series for Sine

[math]\displaystyle{ \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) / board1.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) / board2.factorial(2*i);
    }
    return val;
  }, -10, 10],{strokeColor: "#009900"});						
board2.unsuspendUpdate();

References