Differential equations: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 3: Line 3:
var P = brd.create('point',[0,0], {name:'x_0'});
var P = brd.create('point',[0,0], {name:'x_0'});
var f = function(t,x) {
var f = function(t,x) {
       return 3*x;
       return [3*x[0]];
     };
     };


function ode() {
function ode() {
  var I = [0, 25];
   var data = JXG.Math.Numerics.rungeKutta(JXG.Math.Numerics.predefinedButcher.Heun, [1], [0, 2], 20, f);
  var N = 1000;
}
  var x0 = P.Y();
   var data = JXG.Math.Numerics.rungeKutta(JXG.Math.Numerics.predefinedButcher.Euler, x0, I, N, f);
  var t = [];
  var q = I[0];
  var h = (I[1]-I[0])/N;
  for(var i=0; i<data.length; i++) {
      data[i].push(q);
      q += h;
  }
  return data;
};


var g = brd.createElement('curve', [[0],[0]], {strokeColor:'red', strokeWidth:'2px'});
var g = brd.createElement('curve', [[0],[0]], {strokeColor:'red', strokeWidth:'2px'});
g.updateDataArray = function() {
g.updateDataArray = function() {
     var data = ode();
     var data = ode();
    var h = 0.1;
     this.dataX = [];
     this.dataX = [];
     this.dataY = [];
     this.dataY = [];
     for(var i=0; i<data.length; i++) {
     for(var i=0; i<data.length; i++) {
         this.dataX[i] = data[i][2];
         this.dataX[i] = i*h;
         this.dataY[i] = data[i][0];
         this.dataY[i] = data[i][0];
     }
     }

Revision as of 09:30, 14 July 2010

The underlying JavaScript code