Debian Codegraph @

examples/adg/ode.html

raw
1 <html>
2 <head>
3 <title>ODE | JSXGraph Example</title>
4 <link rel="stylesheet" type="text/css" href="../../distrib/jsxgraph.css" />
5 <script type="text/javascript" src="../../distrib/jsxgraphcore.js"></script>
6 </head>
7 <body>
8 <div id="debug" style="display: none"></div>
9 <center>
10 <div style="width: 1000px;">
11 <div style="width:600px; height: 410px;">
12 <div id="jxgbox" class="jxgbox" style="width:600px; height:400px; text-align: left; float: left;"></div>
13 <div id="polynomials" style="display: none; width: 600px; height: 400px; margin-left: 10px; text-align: left; padding-left: -200px;"></div>
14 </div>
15
16 <div style="width: 800px; margin-top: 10px;">
17 <form>
18 f<sub>1</sub>(x,y1,y2)=<input type="text" id="odeinput1" value="y1+y2"><br />
19 f<sub>2</sub>(x,y1,y2)=<input type="text" id="odeinput2" value="y2+1"><input type=button value="ok" onclick="doIt()">
20 </form>
21 </div>
22 </div>
23 </center>
24 <script type="text/javascript">
25 /* <![CDATA[ */
26
27 var brd = JXG.JSXGraph.initBoard('jxgbox', {axis:true, boundingbox:[-11,11,11,-11]});
28 var N = brd.create('slider',[[-7,9.5],[7,9.5],[-15,10,15]], {name:'N'});
29 var P1 = brd.create('point',[1,-1], {name:'(x_0,c_1)'});
30 var line = brd.create('line',[function(){return -P1.X();},function(){return 1;},function(){return 0;}],{visible:false});
31 var P2 = brd.create('glider',[1,-0.5,line], {name:'(x_0,c_2)'});
32
33 function doIt() {
34 var txt1 = JXG.GeonextParser.geonext2JS(document.getElementById("odeinput1").value);
35 var txt2 = JXG.GeonextParser.geonext2JS(document.getElementById("odeinput2").value);
36 f = new Function("x", "yy", "var y1 = yy[0], y2 = yy[1]; var z1 = " + txt1 + "; var z2 = " + txt2 + "; return [z1,z2];");
37 brd.update();
38 }
39
40 function ode() {
41 return JXG.Math.Numerics.rungeKutta(JXG.Math.Numerics.predefinedButcher.Heun, [P1.Y(),P2.Y()], [P1.X(), P1.X()+N.Value()], 200, f);
42 }
43
44 var g1 = brd.createElement('curve', [[0],[0]], {strokeColor:'red', strokeWidth:'2px', name:'y_1', withLabel:false});
45 var g2 = brd.createElement('curve', [[0],[0]], {strokeColor:'black', strokeWidth:'2px', name:'y_2', withLabel:false});
46 g1.updateDataArray = function() {
47 var data = ode();
48 var h = N.Value()/200;
49 this.dataX = [];
50 this.dataY = [];
51 for(var i=0; i<data.length; i++) {
52 this.dataX[i] = P1.X()+i*h;
53 this.dataY[i] = data[i][0];
54 }
55 };
56 g2.updateDataArray = function() {
57 var data = ode();
58 var h = N.Value()/200;
59 this.dataX = [];
60 this.dataY = [];
61 for(var i=0; i<data.length; i++) {
62 this.dataX[i] = P2.X()+i*h;
63 this.dataY[i] = data[i][1];
64 }
65 };
66 doIt();
67
68 /* ]]> */
69 </script>
70 <br/>
71 </body>
72 </html>