Giter Site home page Giter Site logo

simplerk4's Introduction

SimpleRK4

C++ implementation of a 4th-order Runge-Kutta numerical solver for systems of 1st order differential equations.

Description

Accepts arbitrary number and type of equations as input, returns vector of variable values over time; useful for state-space representations of dynamical systems.

How to use

After including the files (rk4.h and the accompanying implementations in rk4.cpp), declare your differential equations as functions accepting a vector<double> (state of the system) and a double (time), while returning a double. For example,

    double dxdt(std::vector<double> state, double time) {
        double derivative;
        //some code here to calculate the derivative of x given the state and/or time
        return derivative;
    }

Then in the main function, create a vector of function pointers to store your derivatives, like

    std::vector<double (*)(std::vector<double>, double)> diffeqs;
    diffeqs.push_back(dxdt);
    diffeqs.push_back(dydt);

Also create a vector<double> to store your initial state.

Now, instantiate an rk4::rk4Solve with your initial state vector, starting time, size of time step, and derivative functions (note the number of state variables and number of equations governing them must match):

    rk4::rk4Solve Solver(stateInitial, 0.0, 0.02, diffeqs);

Calling iterate() will move the system forward by one timestep, returning a vector of the new state variables.

See demo code for details, in this case solving the equations of motion of a double pendulum.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.