Secant and tangent: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 16: Line 16:
         p[2] = board.createElement('point', [2,0.5], {style:4});
         p[2] = board.createElement('point', [2,0.5], {style:4});
         p[3] = board.createElement('point', [6,5], {style:4});
         p[3] = board.createElement('point', [6,5], {style:4});
         var polynomial = function(x) {
         var pol = board.lagrangePolynomial(p);
                var i;
         graph = board.createElement('curve', ['x', pol, 'x', -10, 10], {curveType:'graph'});
                var y = 0.0;
                var xc = [];
                for (i=0;i<p.length;i++) {
                  xc[i] = p[i].X();
                }
                for (i=0;i<p.length;i++) {
                  var t = p[i].Y();
                  for (var k=0;k<p.length;k++) {
                    if (k!=i) {
                      t *= (x-xc[k])/(xc[i]-xc[k]);
                    }
                  }
                  y += t;
                }
                return y;
            };
         graph = board.createElement('curve', ['x', polynomial, 'x', -10, 10], {curveType:'graph'});


q = board.createElement('glider', [4.5,0,graph], {style:6});
q = board.createElement('glider', [4.5,0,graph], {style:6});
s = board.createElement('slider', [[0,-3],[4,-3],[0.001,1,1]],{name:' '});
s = board.createElement('slider', [[0,-3],[4,-3],[0.001,1,1]],{name:' '});
q2 = board.createElement('point', [function(){ return q.X()+Math.max(s.X(),0.01);},
q2 = board.createElement('point', [function(){ return q.X()+Math.max(s.X(),0.01);},
       function(){ return polynomial(q.X()+Math.max(s.X(),0.01));}], {style:7});
       function(){ return pol(q.X()+Math.max(s.X(),0.01));}], {style:7});
e = board.createElement('point', [function(){ return q2.X()-q.X();},
e = board.createElement('point', [function(){ return q2.X()-q.X();},
       function(){ return (q2.Y()-q.Y())/(q2.X()-q.X());}], {style:7,name:'Sekantensteigung',trace:true});
       function(){ return (q2.Y()-q.Y())/(q2.X()-q.X());}], {style:7,name:'Sekantensteigung',trace:true});

Revision as of 19:12, 4 February 2009