File: diffeq.html

package info (click to toggle)
jsxgraph 1.3.5+dfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 26,044 kB
  • sloc: xml: 5,869; java: 1,072; python: 747; php: 192; makefile: 146; sh: 47
file content (82 lines) | stat: -rw-r--r-- 3,566 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="../distrib/jsxgraph.css" />
        <script type="text/javascript" src="/javascript/prototype/prototype.js"></script>
        <script type="text/javascript" src="../src/loadjsxgraph.js"></script>
   </head>
     <body>
        <h1>Epidemien - SIR model without vital dynamics</h1>
        <span style="color:Blue">Blue: Susceptible population rate</span><br>
        <span style="color:red">Red: Infected population rate</span><br>
        <span style="color:green">Green: Recovered population rate (which means: immune, isolated or dead)</span><br>
        <form><input type="button" value="clear and run" onClick="clearturtle();run()"></form>
        <div id="jsxgbox" class="jxgbox" style="width:600px; height:600px;"></div>
        <script type="text/javascript">
            var brd = JXG.JSXGraph.initBoard('jsxgbox', {originX: 20, originY: 300, unitX: 20, unitY: 250});
            
            var S = brd.createElement('turtle',[],{strokeColor:'blue',strokeWidth:3});
            var I = brd.createElement('turtle',[],{strokeColor:'red',strokeWidth:3});
            var R = brd.createElement('turtle',[],{strokeColor:'green',strokeWidth:3});
            
            var xaxis = brd.createElement('axis', [[0,0], [1,0]], {});
            var yaxis = brd.createElement('axis', [[0,0], [0,1]], {});
            
            var s = brd.createElement('slider', [[0,-0.5], [10,-0.5],[0,0.03,1]], {name:'s'});
            brd.createElement('text', [12,-0.5, "initially infected population rate"]);
            var beta = brd.createElement('slider', [[0,-0.6], [10,-0.6],[0,0.5,1]], {name:'&beta;'});
            brd.createElement('text', [12,-0.6, "&beta;: infection rate"]);
            var gamma = brd.createElement('slider', [[0,-0.7], [10,-0.7],[0,0.3,1]], {name:'&gamma;'});
            brd.createElement('text', [12,-0.7, "&gamma;: recovery rate"]);

            brd.createElement('text', [12,-0.4, function() {return "I(t)="+Math.round(I.pos[1],3);}]);
            
            S.hideTurtle();
            I.hideTurtle();
            R.hideTurtle();
            
            function clearturtle() {
                S.cs();
                I.cs();
                R.cs();
                S.hideTurtle();
                I.hideTurtle();
                R.hideTurtle();
            }
            
            function run() {
                S.setPos(0,1.0-s.Value());
                R.setPos(0,0);
                I.setPos(0,s.X());
                
                delta = 0.1; // global
                t = 0.0;  // global
                loop();
             }
             
             function turtleMove(turtle,dx,dy) {
                turtle.lookTo([1.0+turtle.pos[0],dy+turtle.pos[1]]);
                turtle.fd(dx*Math.sqrt(1+dy*dy));
             }
             
             function loop() {
                var dS = -beta.Value()*S.pos[1]*I.pos[1];
                var dR = gamma.Value()*I.pos[1];
                var dI = -(dS+dR);
                turtleMove(S,delta,dS);
                turtleMove(R,delta,dR);
                turtleMove(I,delta,dI);
                
                t += delta;
                if (t<20.0 && I.pos[1]) {
                    setTimeout(loop,10);
                }
             }
             

//*/
        </script>
        <p>
        Hong Kong flu: initially 7.9 million people, 10 infected, 0 recovered. Thus S(0) = 1, I(0) = 1.27E-6, R(0) = 0, see http://www.cs.princeton.edu/introcs/94diffeq/.
     </body>
</html>