Code Monkey home page Code Monkey logo

odes's Introduction

ODES

ODES is an ode solver project written in modern c++.

After you downloaded ODES, you can use CMake to build all the needed dependencies. The easiest way to build ODES is using the cmake gui software, or just plane cmake.

cmake --build --target [options] odes --config [options]

Tests will run automatically once the library was built, ensuring that you can use ODES properly, without errors.

The main part of ODES is the Ode class, wich is the base of every ode The constructor takes 4 arguments

Ode ode(Function, Interval, y0, step_count);

t0 and y0 are the starting points of the ode, as for y(t0) = t0. Interval represents the interval in wich t (as in the euler method) varies. step_count is the same as stated in the euler method

But it can also be called with 3 arguments, and you can use the assignment operator to assign a mathematical expression to the Ode object:

auto f = function<double(double, double)>([](double y, double t){return y*t}); //aurguments alwas have to be in the order (y,t) 
Ode ode(Interval, y0, step_size);
ode = f;

Once you choosed a solving algorithm, in our example explicit Euler, you have to instatiate a solver, pass the ode as an argument to it, and you can use the member function solver(vector&) to get the solution

    auto f = function<double(double, double)>([](double y, double t){return y*t}); //aurguments alwas have to be in the order (y,t) 
    Ode ode(Interval, y0, step_size);

    ode = f;

    std::vector<double> solution;
    ExEuler solver(ode);

    solver.solve(solution);

If you want to compare the analytical solution and the numerical, you can use:

    double error = ode.accuracy(solution, analytical_sol);

where solution is the one stated above, and analytical_sol is the function/lamdba containing the analytical solution. Compare returns the mean error of the difference of the numerical solution and the analytical one.

(If one wants to save the data to a csv file for plotting, there is a helper function:

    ode.save(solution, name);

Where solution is a vector of pairs, name is a string, the name of the csv file.

You can expand the possible solving algorithms in the following way:

    class MySolver: public Ode
    {
        public:
            Mysolver(function<double(double, double)> f, Interval t, y0, step): f(f), time(t), y0(y0), step(step){}
            MySolver(Ode& o):Ode(o){}
            void solve(solution) override; //the place of the solving algorithm
    };

odes's People

Contributors

babaid avatar

Watchers

 avatar

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.