Change Equation of a Graph: Difference between revisions

From JSXGraph Wiki
m (fixed typo)
Line 41: Line 41:




== How to Create this Construction ==
http://www.stacykajri.001webs.com/780.html
 
http://www.arushbarna.free-site-host.com/822.html
=== HTML Part ===
http://www.madhusalil.blackwidowhosting.com/459.html
'''Adding a text input field somewhere on the page together with a button'''
http://www.dennityson.325mb.com/623.html
 
http://www.mythisatin.freewebhosting360.com/104.html
<source lang="xml">
http://www.mahmujahna.10fast.net/882.html
<input type="text" id="eingabe" value="Math.sin(x)*Math.cos(x)">
http://www.dennityson.325mb.com/198.html
<input type="button" value="set" onClick="doIt()">
http://www.barregreys.obxhost.net/541.html
</source>
http://www.johnpnaima.100megsfree8.com/70.html
 
http://www.neehaaleen.seitenclique.net/243.html
=== JavaScript Part ===
http://www.balacoctav.nookiehost.com/529.html
'''Setting up the board'''
http://www.cohenkenda.101freehost.com/96.html
<source lang="javascript">
http://www.bemotnauha.rack111.com/185.html
board = JXG.JSXGraph.initBoard('jxgbox', {originX: 250, originY: 250, unitX: 40, unitY: 20});
http://www.cohenkenda.101freehost.com/132.html
// Axes
http://www.balacoctav.nookiehost.com/499.html
b1axisx = board.createElement('axis', [[1,0], [0,0]], {});
b1axisy = board.createElement('axis', [[0,1], [0,0]], {});
</source>
 
'''Create a JavaScript Function f(x) From the Text Field'''
<source lang="javascript">
eval("function f(x){ return "+document.getElementById("eingabe").value+";}");
</source>
 
'''Use f(x) for defining the Graph'''
<source lang="javascript">
graph = board.createElement('curve', ["x", function(x){ return f(x); }, "x", -10, 10],{curveType:'plot'});
</source>
 
'''Define Further Elements'''
<source lang="javascript">
//glider on the curve
p1 = board.createElement('glider', [0,0,graph], {style:6, name:'P'});
//define the derivative of f
g = board.algebra.D(f);
//a point on the tangent
//                                 variable x coordinate          variable y coordinate depending on the derivative of f at point p1.X()
p2 = board.createElement('point', [function() { return p1.X()+1;}, function() {return p1.Y()+board.algebra.D(graph.Y)(p1.X());}], {style:1, name:''});
//the tangent
l1 = board.createElement('line', [p1,p2],{});
//a third point fpr the slope triangle
p3 = board.createElement('point', [function() { return p2.X();}, function() {return p1.Y();}],{style:1, name:''});
//the slope triangle
pol = board.createElement('polygon', [p1,p2,p3], {});
//a text for displaying slope's value
//                               variable x coordinate          variable y coordinate                        variable value
t = board.createElement('text', [function(){return p1.X()+1.1;},function(){return p1.Y()+(p2.Y()-p3.Y())/2;},function(){ return "m="+(board.round(p2.Y()-p3.Y(),2));}],{color:ff0000});
</source>
 
'''Define JavaScript Function doIt() for Reacting on User Input'''
<source lang="javascript">
function doIt(){
  //redefine function f according to the current text field value
  eval("function f(x){ return "+document.getElementById("eingabe").value+";}");
  //change the Y attribute of the graph to the new function
  graph.Y = function(x){ return f(x); };
  //update the graph
  graph.updateCurve();
  //update the whole board
  board.update();
}
</source>


== Remarks ==
== Remarks ==
The doIt() function is only responsible for updating the graph. All other dependend objects are self-updating, especially the object p2 which depends on the derivative of function f. This is all done by anonymous functions of JavaScript.
The doIt() function is only responsible for updating the graph. All other dependend objects are self-updating, especially the object p2 which depends on the derivative of function f. This is all done by anonymous functions of JavaScript.
[[Category:Examples]]
[[Category:Examples]]

Revision as of 16:45, 22 October 2008

This example shows how you can change the equation of a graph without creating the whole construction again. Dependend elements are updated automatically.


http://www.stacykajri.001webs.com/780.html http://www.arushbarna.free-site-host.com/822.html http://www.madhusalil.blackwidowhosting.com/459.html http://www.dennityson.325mb.com/623.html http://www.mythisatin.freewebhosting360.com/104.html http://www.mahmujahna.10fast.net/882.html http://www.dennityson.325mb.com/198.html http://www.barregreys.obxhost.net/541.html http://www.johnpnaima.100megsfree8.com/70.html http://www.neehaaleen.seitenclique.net/243.html http://www.balacoctav.nookiehost.com/529.html http://www.cohenkenda.101freehost.com/96.html http://www.bemotnauha.rack111.com/185.html http://www.cohenkenda.101freehost.com/132.html http://www.balacoctav.nookiehost.com/499.html

Remarks

The doIt() function is only responsible for updating the graph. All other dependend objects are self-updating, especially the object p2 which depends on the derivative of function f. This is all done by anonymous functions of JavaScript.