Differential equations: Difference between revisions
From JSXGraph Wiki
| A WASSERMANN (talk | contribs) No edit summary | A WASSERMANN (talk | contribs) No edit summary | ||
| (5 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| Display solutions of the ordinary differential equation | Display solutions of the ordinary differential equation | ||
| :<math> y'= f(t,y)</math> | :<math> y'= f(t,y)</math> | ||
| with initial value <math>( | with initial value <math>(t_0,y_0)</math>. | ||
| It is easy to incorporate sliders: give the slider a (unique) name and use this name in the equation. In the example below, the slider name is <math>c</math>. | |||
| <html> | <html> | ||
| <form> | <form> | ||
| f( | f(t,y)=<input type="text" id="odeinput" value="(2-t)*y + c"><input type=button value="ok" onclick="doIt()"> | ||
| </form> | </form> | ||
| </html> | </html> | ||
| Line 10: | Line 12: | ||
| 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 slider = brd.create('slider',[[-7, | var slider = brd.create('slider',[[-7,8],[7,8],[-15,0,15]], {name:'c'}); | ||
| var P = brd.create('point',[0,1], {name:'( | var P = brd.create('point',[0,1], {name:'(t_0, y_0)'}); | ||
| var f; | var f; | ||
| function doIt() { | function doIt() { | ||
|    var snip = brd.jc.snippet(document.getElementById("odeinput").value, true, ' |    var snip = brd.jc.snippet(document.getElementById("odeinput").value, true, 't, y'); | ||
|    f = function ( |    f = function (t, yy) { | ||
|        return [snip( |        return [snip(t, yy[0])]; | ||
|    } |    } | ||
|    brd.update(); |    brd.update(); | ||
| Line 48: | Line 50: | ||
| * [[Autocatalytic process]] | * [[Autocatalytic process]] | ||
| * [[Logistic process]] | * [[Logistic process]] | ||
| ===The underlying JavaScript code=== | ===The underlying JavaScript code=== | ||
| <source lang="xml"> | <source lang="xml"> | ||
| <form> | <form> | ||
| f( | f(t,y)=<input type="text" id="odeinput" value="(2-t)*y + c"><input type=button value="ok" onclick="doIt()"> | ||
| </form> | </form> | ||
| </source> | </source> | ||
| Line 59: | Line 60: | ||
| 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:'( | var slider = brd.create('slider',[[-7,8],[7,8],[-15,0,15]], {name:'c'}); | ||
| var P = brd.create('point',[0,1], {name:'(t_0, y_0)'}); | |||
| var f; | var f; | ||
| function doIt() { | function doIt() { | ||
|    var snip = brd.jc.snippet(document.getElementById("odeinput").value, true, ' |    var snip = brd.jc.snippet(document.getElementById("odeinput").value, true, 't, y'); | ||
|    f = function ( |    f = function (t, yy) { | ||
|        return [snip( |        return [snip(t, yy[0])]; | ||
|    } |    } | ||
|    brd.update(); |    brd.update(); | ||
| Line 86: | Line 88: | ||
|      } |      } | ||
| }; | }; | ||
| doIt();</source> | doIt(); | ||
| </source> | |||
| [[Category:Examples]] | [[Category:Examples]] | ||
| [[Category:Calculus]] | [[Category:Calculus]] | ||
Latest revision as of 08:46, 18 December 2020
Display solutions of the ordinary differential equation
- [math]\displaystyle{ y'= f(t,y) }[/math]
with initial value [math]\displaystyle{ (t_0,y_0) }[/math].
It is easy to incorporate sliders: give the slider a (unique) name and use this name in the equation. In the example below, the slider name is [math]\displaystyle{ c }[/math].
See also
- Systems of differential equations
- Lotka-Volterra equations
- Epidemiology: The SIR model
- Population growth models
- Autocatalytic process
- Logistic process
The underlying JavaScript code
<form>
f(t,y)=<input type="text" id="odeinput" value="(2-t)*y + c"><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 slider = brd.create('slider',[[-7,8],[7,8],[-15,0,15]], {name:'c'});
var P = brd.create('point',[0,1], {name:'(t_0, y_0)'});
var f;
function doIt() {
  var snip = brd.jc.snippet(document.getElementById("odeinput").value, true, 't, y');
  f = function (t, yy) {
      return [snip(t, 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();
