Continuous functions: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
 
(35 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<html>
<jsxgraph width="600" height="500" box="box">
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
  var board = JXG.JSXGraph.initBoard('box', {boundingbox: [-4, 6, 6, -4], axis: true});
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
  board.suspendUpdate();
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
 
<div id="box" class="jxgbox" style="width:600px; height:500px;"></div>
  var f = function(x) {
<script language="JavaScript">
  board = JXG.JSXGraph.initBoard('box', {originX: 300, originY: 250, unitX: 50, unitY: 50});
b1axisx = board.createElement('axis', [[0,0], [1,0]], {});
  b1axisy = board.createElement('axis', [[0,0], [0,1]], {});
  graph = board.createElement('curve', ['x',
    function(x) {
       if (x<1) {
       if (x<1) {
           return 0.5*x*x;
           return 0.5*x*x;
Line 15: Line 9:
         return x+1;
         return x+1;
       }
       }
       }, 'x'], {curveType:'graph',strokeColor:'#00ff00'});
       };
var graph = board.create('functiongraph', [f], {strokeColor:'#0000ff'});
 
var s = board.create('slider', [[0,-1],[4,-1],[0,1,1]],{name:'&delta;'});


      s = board.createElement('slider', [0,-2,1,0,1,1],{name:' '});
var x1 = board.create('glider', [-2,0,board.defaultAxes.x],{name:'a'});
board.suspendUpdate();
var x2 = board.create('point', [function(){return x1.X()-s.Value();},0],{size:2,face:'[]',name:' '});
var x3 = board.create('point', [function(){return x1.X()+s.Value();},0],{size:2,face:'[]',name:' '});
var y1 = board.create('point', [function(){return x1.X();},function(){return f(x1.X());}],{size:2,face:'[]',name:'f(a)'});
var y2 = board.create('point', [function(){return x2.X();},function(){return f(x2.X());}],{size:2,face:'[]',name:' '});
var y3 = board.create('point', [function(){return x3.X();},function(){return f(x3.X());}],{size:2,face:'[]',name:' '});
var v1 = board.create('segment', [x1,y1],{strokeColor:'gray',dash:2,strokeWidth:1});
var v2 = board.create('line', [x2,y2],{strokeColor:'gray',dash:2,strokeWidth:1});
var v3 = board.create('line', [x3,y3],{strokeColor:'gray',dash:2,strokeWidth:1});


      x1 = board.createElement('glider', [-2,0,b1axisx],{name:' '});
var h1 = board.create('curve', [function(t){return t},function(t){return y1.Y();}], {strokeColor:'gray',dash:2,strokeWidth:1});
      //x1 = board.createElement('glider', [-2,0,b1axisx],{name:' '});
var h2 = board.create('curve', [function(t){return t},function(t){return y2.Y();}], {strokeColor:'gray',dash:2,strokeWidth:1});
var h3 = board.create('curve', [function(t){return t},function(t){return y3.Y();}], {strokeColor:'gray',dash:2,strokeWidth:1});


</script>
var txt = board.create('text', [4.2, -1.5, function() {
</html>
            return '&epsilon; = ' + Math.max(Math.abs(y2.Y() - y1.Y()), Math.abs(y1.Y() - y3.Y())).toFixed(5);
          }], {strokeColor: 'blue'});
board.unsuspendUpdate();
</jsxgraph>


=== References ===
=== References ===
* [http://en.wikipedia.org/wiki/Continuous_function http://en.wikipedia.org/wiki/Continuous_function]


=== The underlying JavaScript source code ===
=== The underlying JavaScript source code ===


<source lang="javascript">
<source lang="javascript">
var board = JXG.JSXGraph.initBoard('box', {boundingbox: [-4, 6, 6, -4], axis: true});
board.suspendUpdate();
var f = function(x) {
      if (x<1) {
          return 0.5*x*x;
      } else {
        return x+1;
      }
      };
var graph = board.create('functiongraph', [f], {strokeColor:'#0000ff'});
var s = board.create('slider', [[0,-1],[4,-1],[0,1,1]],{name:'&delta;'});
var x1 = board.create('glider', [-2,0,board.defaultAxes.x],{name:'a'});
board.suspendUpdate();
var x2 = board.create('point', [function(){return x1.X()-s.Value();},0],{size:2,face:'[]',name:' '});
var x3 = board.create('point', [function(){return x1.X()+s.Value();},0],{size:2,face:'[]',name:' '});
var y1 = board.create('point', [function(){return x1.X();},function(){return f(x1.X());}],{size:2,face:'[]',name:'f(a)'});
var y2 = board.create('point', [function(){return x2.X();},function(){return f(x2.X());}],{size:2,face:'[]',name:' '});
var y3 = board.create('point', [function(){return x3.X();},function(){return f(x3.X());}],{size:2,face:'[]',name:' '});
var v1 = board.create('segment', [x1,y1],{strokeColor:'gray',dash:2,strokeWidth:1});
var v2 = board.create('line', [x2,y2],{strokeColor:'gray',dash:2,strokeWidth:1});
var v3 = board.create('line', [x3,y3],{strokeColor:'gray',dash:2,strokeWidth:1});
var h1 = board.create('curve', [function(t){return t},function(t){return y1.Y();}], {strokeColor:'gray',dash:2,strokeWidth:1});
var h2 = board.create('curve', [function(t){return t},function(t){return y2.Y();}], {strokeColor:'gray',dash:2,strokeWidth:1});
var h3 = board.create('curve', [function(t){return t},function(t){return y3.Y();}], {strokeColor:'gray',dash:2,strokeWidth:1});
var txt = board.create('text', [4.2, -1.5, function() {
            return '&epsilon; = ' + Math.max(Math.abs(y2.Y() - y1.Y()), Math.abs(y1.Y() - y3.Y())).toFixed(5);
          }], {strokeColor: 'blue'});
board.unsuspendUpdate();
</source>
</source>


[[Category:Examples]]
[[Category:Examples]]
[[Category:Calculus]]

Latest revision as of 19:02, 7 January 2019

References

The underlying JavaScript source code

 var board = JXG.JSXGraph.initBoard('box', {boundingbox: [-4, 6, 6, -4], axis: true});
 board.suspendUpdate();

 var f = function(x) {
       if (x<1) {
          return 0.5*x*x;
       } else {
         return x+1;
       }
      };
 var graph = board.create('functiongraph', [f], {strokeColor:'#0000ff'});

 var s = board.create('slider', [[0,-1],[4,-1],[0,1,1]],{name:'&delta;'});

 var x1 = board.create('glider', [-2,0,board.defaultAxes.x],{name:'a'});
 board.suspendUpdate();
 var x2 = board.create('point', [function(){return x1.X()-s.Value();},0],{size:2,face:'[]',name:' '});
 var x3 = board.create('point', [function(){return x1.X()+s.Value();},0],{size:2,face:'[]',name:' '});
 var y1 = board.create('point', [function(){return x1.X();},function(){return f(x1.X());}],{size:2,face:'[]',name:'f(a)'});
 var y2 = board.create('point', [function(){return x2.X();},function(){return f(x2.X());}],{size:2,face:'[]',name:' '});
 var y3 = board.create('point', [function(){return x3.X();},function(){return f(x3.X());}],{size:2,face:'[]',name:' '});
 var v1 = board.create('segment', [x1,y1],{strokeColor:'gray',dash:2,strokeWidth:1});
 var v2 = board.create('line', [x2,y2],{strokeColor:'gray',dash:2,strokeWidth:1});
 var v3 = board.create('line', [x3,y3],{strokeColor:'gray',dash:2,strokeWidth:1});

 var h1 = board.create('curve', [function(t){return t},function(t){return y1.Y();}], {strokeColor:'gray',dash:2,strokeWidth:1});
 var h2 = board.create('curve', [function(t){return t},function(t){return y2.Y();}], {strokeColor:'gray',dash:2,strokeWidth:1});
 var h3 = board.create('curve', [function(t){return t},function(t){return y3.Y();}], {strokeColor:'gray',dash:2,strokeWidth:1});

 var txt = board.create('text', [4.2, -1.5, function() {
            return '&epsilon; = ' + Math.max(Math.abs(y2.Y() - y1.Y()), Math.abs(y1.Y() - y3.Y())).toFixed(5); 
           }], {strokeColor: 'blue'});
 board.unsuspendUpdate();