Difference between revisions of "Differential equations"

From JSXGraph Wiki
Jump to: navigation, search
Line 1: Line 1:
 
Display solutions of the ordinary differential equation
 
Display solutions of the ordinary differential equation
:<math> y'= f(x,y)</math>
+
:<math> y'= f(t,y)</math>
 
with initial value <math>(x_0,y_0)</math>.
 
with initial value <math>(x_0,y_0)</math>.
 
<html>
 
<html>
Line 58: Line 58:
 
var brd = JXG.JSXGraph.initBoard('jxgbox', {axis:true, boundingbox:[-11,11,11,-11]});
 
var brd = JXG.JSXGraph.initBoard('jxgbox', {axis:true, boundingbox:[-11,11,11,-11]});
 
var N = brd.create('slider',[[-7,9.5],[7,9.5],[-15,10,15]], {name:'N'});
 
var N = brd.create('slider',[[-7,9.5],[7,9.5],[-15,10,15]], {name:'N'});
var P = brd.create('point',[0,1], {name:'(x_0,y_0)'});
+
var P = brd.create('point',[0,1], {name:'(x_0, y_0)'});
 +
var f;
  
 
function doIt() {
 
function doIt() {
   var txt = JXG.GeonextParser.geonext2JS(document.getElementById("odeinput").value);
+
   var snip = brd.jc.snippet(document.getElementById("odeinput").value, true, 'x, y');
   f = new Function("x", "yy", "var y = yy[0]; var z = " + txt + "; return [z]");
+
   f = function (x, yy) {
 +
      return [snip(x, yy[0])];
 +
  }
 
   brd.update();
 
   brd.update();
 
}
 
}
Line 74: Line 77:
 
     var data = ode();
 
     var data = ode();
 
     var h = N.Value()/200;
 
     var h = N.Value()/200;
 +
    var i;
 
     this.dataX = [];
 
     this.dataX = [];
 
     this.dataY = [];
 
     this.dataY = [];
     for(var i=0; i<data.length; i++) {
+
     for(i=0; i<data.length; i++) {
 
         this.dataX[i] = P.X()+i*h;
 
         this.dataX[i] = P.X()+i*h;
 
         this.dataY[i] = data[i][0];
 
         this.dataY[i] = data[i][0];
 
     }
 
     }
 
};
 
};
doIt();
+
doIt();</source>
</source>
 
  
 
[[Category:Examples]]
 
[[Category:Examples]]
 
[[Category:Calculus]]
 
[[Category:Calculus]]

Revision as of 13:27, 19 January 2017

Display solutions of the ordinary differential equation

[math] y'= f(t,y)[/math]

with initial value [math](x_0,y_0)[/math].

f(x,y)=

See also

The underlying JavaScript code

<form>
f(x,y)=<input type="text" id="odeinput" value="(2-x)*y"><input type=button value="ok" onclick="doIt()">
</form>
var brd = JXG.JSXGraph.initBoard('jxgbox', {axis:true, boundingbox:[-11,11,11,-11]});
var N = brd.create('slider',[[-7,9.5],[7,9.5],[-15,10,15]], {name:'N'});
var P = brd.create('point',[0,1], {name:'(x_0, y_0)'});
var f;

function doIt() {
  var snip = brd.jc.snippet(document.getElementById("odeinput").value, true, 'x, y');
  f = function (x, yy) {
      return [snip(x, yy[0])];
  }
  brd.update();
}

function ode() {
   return JXG.Math.Numerics.rungeKutta('heun', [P.Y()], [P.X(), P.X()+N.Value()], 200, f);
}

var g = brd.create('curve', [[0],[0]], {strokeColor:'red', strokeWidth:2});
g.updateDataArray = function() {
    var data = ode();
    var h = N.Value()/200;
    var i;
    this.dataX = [];
    this.dataY = [];
    for(i=0; i<data.length; i++) {
        this.dataX[i] = P.X()+i*h;
        this.dataY[i] = data[i][0];
    }
};
doIt();