Rational functions: Difference between revisions
From JSXGraph Wiki
| A WASSERMANN (talk | contribs) No edit summary | A WASSERMANN (talk | contribs) No edit summary | ||
| Line 39: | Line 39: | ||
|            p.push(board.createElement('point',[(Math.random()-0.5)*10,(Math.random()-0.5)*3],{style:6})); |            p.push(board.createElement('point',[(Math.random()-0.5)*10,(Math.random()-0.5)*3],{style:6})); | ||
|            board.update(); |            board.update(); | ||
|         } | |||
|         board2 = JXG.JSXGraph.initBoard('box2', {originX: 150, originY: 200, unitX: 30, unitY: 25}); | |||
|         // Axes | |||
|         b1axisx = board2.createElement('axis', [[0,0], [1,0]], {}); | |||
|         b1axisy = board2.createElement('axis', [[0,0], [0,1]], {}); | |||
|         var q = []; | |||
|         q[0] = board2.createElement('point', [-1,2], {style:6}); | |||
|         q[1] = board2.createElement('point', [3,-1], {style:6}); | |||
|         var polynomial2 = function(x) { | |||
|                 var i; | |||
|                 var y = 0.0; | |||
|                 var xc = []; | |||
|                 for (i=0;i<p.length;i++) { | |||
|                   xc[i] = q[i].X(); | |||
|                 } | |||
|                 for (i=0;i<p.length;i++) { | |||
|                   var t = q[i].Y(); | |||
|                   for (var k=0;k<q.length;k++) { | |||
|                     if (k!=i) { | |||
|                       t *= (x-xc[k])/(xc[i]-xc[k]); | |||
|                     } | |||
|                   } | |||
|                   y += t; | |||
|                 } | |||
|                 return y; | |||
|             }; | |||
|         graph = board2.createElement('curve', ['x', polynomial, 'x', -10, 10], {curveType:'graph'}); | |||
|         function addPoint2() { | |||
|           p.push(board2.createElement('point',[(Math.random()-0.5)*10,(Math.random()-0.5)*3],{style:6})); | |||
|           board2.update(); | |||
|          } |          } | ||
| </script> | </script> | ||
| </html> | </html> | ||
Revision as of 13:18, 15 December 2008
