JSXGraph logo
JSXGraph
JSXGraph share

Share

Systems of differential equations
QR code
<iframe 
    src="https://jsxgraph.org/share/iframe/systems-of-differential-equations" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: Systems of differential equations" 
    allowfullscreen
></iframe>
This code has to
f<sub>1</sub>(x,y1,y2)=<input type="text" id="odeinput1" value="y1+y2"><br />
f<sub>2</sub>(x,y1,y2)=<input type="text" id="odeinput2" value="y2+1"><input type=button value="ok" onclick="doIt()">

<div id="board-0-wrapper" class="jxgbox-wrapper " style="width: 100%; ">
   <div id="board-0" class="jxgbox" style="aspect-ratio: 1 / 1; width: 100%;" data-ar="1 / 1"></div>
</div>

<script type = "text/javascript"> 
    /*
    This example is licensed under a 
    Creative Commons Attribution ShareAlike 4.0 International License.
    https://creativecommons.org/licenses/by-sa/4.0/
    
    Please note you have to mention 
    The Center of Mobile Learning with Digital Technology
    in the credits.
    */
    
    const BOARDID = 'board-0';

    var board = JXG.JSXGraph.initBoard(BOARDID, { axis: true, boundingbox: [-11, 11, 11, -11], keepaspectratio: true });
    var N = board.create('slider', [[-7, 9.5], [7, 9.5], [-15, 10, 15]], { name: 'N' });
    var P1 = board.create('point', [1, -1], { name: '(x_0,c_1)' });
    var line = board.create('line', [function() { return -P1.X(); }, function() { return 1; },
    function() { return 0; }], { visible: false });
    var P2 = board.create('glider', [1, -0.5, line], { name: '(x_0,c_2)' });
    
    var f;
    
    function doIt() {
        var txt1 = document.getElementById("odeinput1").value;
        var txt2 = document.getElementById("odeinput2").value;
    
        var snip1 = board.jc.snippet(txt1, true, 'x, y1, y2');
        var snip2 = board.jc.snippet(txt2, true, 'x, y1, y2');
        f = function(x, yy) {
            return [snip1(x, yy[0], yy[1]), snip2(x, yy[0], yy[1])];
        }
        board.update();
    }
    
    function ode() {
        return JXG.Math.Numerics.rungeKutta('heun', [P1.Y(), P2.Y()], [P1.X(), P1.X() + N.Value()], 200, f);
    }
    
    var g1 = board.create('curve', [[0], [0]], { strokeColor: 'red', strokeWidth: 2, name: 'y_1', withLabel: false });
    var g2 = board.create('curve', [[0], [0]], { strokeColor: 'black', strokeWidth: 2, name: 'y_2', withLabel: false });
    g1.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] = P1.X() + i * h;
            this.dataY[i] = data[i][0];
        }
    };
    
    g2.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] = P2.X() + i * h;
            this.dataY[i] = data[i][1];
        }
    };
    doIt();
 </script> 
/*
This example is licensed under a 
Creative Commons Attribution ShareAlike 4.0 International License.
https://creativecommons.org/licenses/by-sa/4.0/

Please note you have to mention 
The Center of Mobile Learning with Digital Technology
in the credits.
*/

const BOARDID = 'your_div_id'; // Insert your id here!

var board = JXG.JSXGraph.initBoard(BOARDID, { axis: true, boundingbox: [-11, 11, 11, -11], keepaspectratio: true });
var N = board.create('slider', [[-7, 9.5], [7, 9.5], [-15, 10, 15]], { name: 'N' });
var P1 = board.create('point', [1, -1], { name: '(x_0,c_1)' });
var line = board.create('line', [function() { return -P1.X(); }, function() { return 1; },
function() { return 0; }], { visible: false });
var P2 = board.create('glider', [1, -0.5, line], { name: '(x_0,c_2)' });

var f;

function doIt() {
    var txt1 = document.getElementById("odeinput1").value;
    var txt2 = document.getElementById("odeinput2").value;

    var snip1 = board.jc.snippet(txt1, true, 'x, y1, y2');
    var snip2 = board.jc.snippet(txt2, true, 'x, y1, y2');
    f = function(x, yy) {
        return [snip1(x, yy[0], yy[1]), snip2(x, yy[0], yy[1])];
    }
    board.update();
}

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

var g1 = board.create('curve', [[0], [0]], { strokeColor: 'red', strokeWidth: 2, name: 'y_1', withLabel: false });
var g2 = board.create('curve', [[0], [0]], { strokeColor: 'black', strokeWidth: 2, name: 'y_2', withLabel: false });
g1.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] = P1.X() + i * h;
        this.dataY[i] = data[i][0];
    }
};

g2.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] = P2.X() + i * h;
        this.dataY[i] = data[i][1];
    }
};
doIt();

Systems of differential equations

Display solutions of the ordinary differential equation $$y_1'= f_1(x,y_1,y_2)$$ $$y_2'= f_2(x,y_1,y_2)$$ with initial values $(x_0,c_1)$, $(x_0,c_2)$.
f1(x,y1,y2)=
f2(x,y1,y2)=
f<sub>1</sub>(x,y1,y2)=<input type="text" id="odeinput1" value="y1+y2"><br />
f<sub>2</sub>(x,y1,y2)=<input type="text" id="odeinput2" value="y2+1"><input type=button value="ok" onclick="doIt()">
// Define the id of your board in BOARDID

var board = JXG.JSXGraph.initBoard(BOARDID, { axis: true, boundingbox: [-11, 11, 11, -11], keepaspectratio: true });
var N = board.create('slider', [[-7, 9.5], [7, 9.5], [-15, 10, 15]], { name: 'N' });
var P1 = board.create('point', [1, -1], { name: '(x_0,c_1)' });
var line = board.create('line', [function() { return -P1.X(); }, function() { return 1; },
function() { return 0; }], { visible: false });
var P2 = board.create('glider', [1, -0.5, line], { name: '(x_0,c_2)' });

var f;

function doIt() {
    var txt1 = document.getElementById("odeinput1").value;
    var txt2 = document.getElementById("odeinput2").value;

    var snip1 = board.jc.snippet(txt1, true, 'x, y1, y2');
    var snip2 = board.jc.snippet(txt2, true, 'x, y1, y2');
    f = function(x, yy) {
        return [snip1(x, yy[0], yy[1]), snip2(x, yy[0], yy[1])];
    }
    board.update();
}

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

var g1 = board.create('curve', [[0], [0]], { strokeColor: 'red', strokeWidth: 2, name: 'y_1', withLabel: false });
var g2 = board.create('curve', [[0], [0]], { strokeColor: 'black', strokeWidth: 2, name: 'y_2', withLabel: false });
g1.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] = P1.X() + i * h;
        this.dataY[i] = data[i][0];
    }
};

g2.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] = P2.X() + i * h;
        this.dataY[i] = data[i][1];
    }
};
doIt();

license

This example is licensed under a Creative Commons Attribution ShareAlike 4.0 International License.
Please note you have to mention The Center of Mobile Learning with Digital Technology in the credits.