| Reference | Tutorial | Example Code |
| smtk::plotter_2d | interactive phase space plotter |
This example interactively solves the classic Lotka-Volterra model of competition. x = population of rabbits. y = population of sheep.
#include <math.h> #include <smtk.h> #include <smtk/rk4.h> #include <smtk/plotter_2d.h> static double x[2]; // x[0]=x, x[1]=y static double t; // time // The 2 ODEs to solve using this differential equations call-back // function. static void difeq(double *xdot, const double *x, double t) { xdot[0] = x[0]*(3.0 - x[0] - 2*x[1]); xdot[1] = x[1]*(2.0 - x[0] - x[1]); } // Get a ODE solver object. static smtk::rk4<double,double,double> rk4(difeq, // differential equations call-back function 2, // 2 equations 0.04 // time step ); // Initializing callback function. static double *init(double x_in, double y_in, bool &do_draw) { x[0] = x_in; x[1] = y_in; t = 0.0; // time return x; // return the new x,y for the plotter. } // Solving one point, callback function. static double *step(bool &do_draw, bool &show_line) { rk4.go(x, &t); // Go to the next time using the ODE solver. return x; // return the new x,y for the plotter. } int main(void) { smtk::plotter_2d plotter; plotter. set_window_title("Sheep VS Rabbits"). set_callbacks(1, init, step). // pass the call-back functions set_line_width(3). set_point_width(2). set_scale(-0.1, 4.0, -0.1, 3.0). run(); return 0; }
1.5.2