Thanks for the sharing the boost::odeint example, I was not aware of this boost library.Test code
Code: Select all// Interval strategy on (O,inf): // // 1. Truncation to large finite T // 2. Transform (0,inf) to (0,1) // // 2. tends to give more accurate rounded results. // // (C) Datasim Education BV 2020 // #include "LinearSystemGradientDescent.hpp" #include <boost/numeric/ublas/vector.hpp> #include <boost/numeric/ublas/matrix.hpp> #include <boost/numeric/ublas/io.hpp> namespace ublas = boost::numeric::ublas; #include <boost/numeric/odeint.hpp> namespace Bode = boost::numeric::odeint; int main() { // 2X2 matrices // // A1 == symmetric and positive definite (pd) // A2 == symmetric and NOT positive definite (pd) // A3 == NOT symmetric and positive definite(pd) // A4 == NOT symmetric and NOT positive definite(pd) std::size_t r = 2; std::size_t c = 2; ublas::matrix<double> A1(r, c); A1(0, 0) = 2; A1(0, 1) = 1; A1(1, 0) = 1; A1(1, 1) = 2; ublas::vector<double> b1(r); b1[0] = 4; b1[1] = 5; // ODE Solver, x = (1 2) is solution in all cases ublas::vector<double> x(r); x[0] = x[1] = 0.0; ublas::vector<double> x2(r); x2[0] = x2[1] = 0.0; // Integrate on [L,T] // EXX. Try T = 0.1 0.25, 0.5, 0.75, 0.95. 0.9999 etc. double L = 0.0; double T = 0.99584959825795; double dt = 1.0e-5; LinearSystemGradientDescentOde ode(A1, b1); // Cash Karp (Ford Cortina) std::size_t steps = Bode::integrate(ode, x, L, T, dt); std::cout << "Number of steps " << steps << '\n'; std::cout << "Solution " << x << '\n'; // BS upmarket model Bode::bulirsch_stoer<state_type, value_type> bsStepper; std::size_t steps3 = Bode::integrate_adaptive(bsStepper, ode, x2, L, T, dt); std::cout << "Number of steps, Bulirsch-Stoer " << steps3 << '\n'; std::cout << "Solution II " << x2 << '\n'; return 0; }
By the way, reading the posts, I am not sure to understand your point. Is not SGD an optimization method, as all those present in boost::odeint ? Isn'it this discussion equivalent to compare for instance a Godunov scheme to a glimm one for numerical analysis of PDEs ?