Differential equations: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary |
A WASSERMANN (talk | contribs) No edit summary |
||
Line 4: | Line 4: | ||
<html> | <html> | ||
<form> | <form> | ||
f(x,y)=<input type="text" id="odeinput" value="(2-x)*y"><input type=button value="ok" onclick="doIt()"> | f(x,y)=<input type="text" id="odeinput" value="(2-x)*y + c"><input type=button value="ok" onclick="doIt()"> | ||
</form> | </form> | ||
</html> | </html> | ||
Line 10: | Line 10: | ||
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,8],[7,8],[-15, | var slider = brd.create('slider',[[-7,8],[7,8],[-15,0,15]], {name:'c'}); | ||
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; | var f; | ||
Line 59: | Line 59: | ||
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,8],[7,8],[-15,0,15]], {name:'c'}); | |||
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; | var f; | ||
Line 86: | Line 87: | ||
} | } | ||
}; | }; | ||
doIt();</source> | doIt(); | ||
</source> | |||
[[Category:Examples]] | [[Category:Examples]] | ||
[[Category:Calculus]] | [[Category:Calculus]] |
Revision as of 11:37, 19 January 2017
Display solutions of the ordinary differential equation
- [math]\displaystyle{ y'= f(t,y) }[/math]
with initial value [math]\displaystyle{ (x_0,y_0) }[/math].
See also
- Systems of differential equations
- Lotka-Volterra equations
- Epidemiology: The SIR model
- Population growth models
- Autocatalytic process
- Logistic process
- Paul Pearson has written a very nice variation: Slope fields and solution curves (using the Runge-Kutta)
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 slider = brd.create('slider',[[-7,8],[7,8],[-15,0,15]], {name:'c'});
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();