# Difference between revisions of "Differential equations"

From JSXGraph Wiki

Jump to navigationJump to searchA WASSERMANN (talk | contribs) |
A WASSERMANN (talk | contribs) |
||

Line 43: | Line 43: | ||

* [[Autocatalytic process]] | * [[Autocatalytic process]] | ||

* [[Logistic process]] | * [[Logistic process]] | ||

− | * Paul | + | * Paul Pearson has written a very nice variation: [http://faculty.fortlewis.edu/Pearson_P/jsxgraph/slopefield.html Slope fields and solution curves (using the Runge-Kutta)] |

===The underlying JavaScript code=== | ===The underlying JavaScript code=== |

## Revision as of 16:58, 11 January 2011

Display solutions of the ordinary differential equation

- [math] y'= f(x,y)[/math]

with initial value [math](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 P = brd.create('point',[0,1], {name:'(x_0,y_0)'});
function doIt() {
var txt = JXG.GeonextParser.geonext2JS(document.getElementById("odeinput").value);
f = new Function("x", "yy", "var y = yy[0]; var z = " + txt + "; return [z]");
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:'2px'});
g.updateDataArray = function() {
var data = ode();
var h = N.Value()/200;
this.dataX = [];
this.dataY = [];
for(var i=0; i<data.length; i++) {
this.dataX[i] = P.X()+i*h;
this.dataY[i] = data[i][0];
}
};
doIt();
```