tmainB.cpp - numeric - C++ library with numerical algorithms
 (HTM) git clone git://src.adamsgaard.dk/numeric
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
       tmainB.cpp (1386B)
       ---
            1 #include <iostream>
            2 #include <vector>
            3 #include <complex>
            4 #include <cmath>
            5 #include "typedefs.h"
            6 #include "check.h"
            7 #include "ode.h"
            8 #include "functions.h"
            9 
           10 int main()
           11 {
           12   // Namespace declarations
           13   using std::cout;
           14   using std::vector;
           15   using std::complex;
           16 
           17   // Calculate machine precision
           18   Floattype eps_machine = 1.0f;
           19   while (1.0f + eps_machine != 1.0f)
           20     eps_machine /= 2.0f;
           21   
           22   cout << "\n\033[1;33m--- Part B: Solving along an imaginary path ---\033[0m\n";
           23   complex<Floattype> a(0.0f, 0.0f);        // Lower limit
           24   complex<Floattype> b(0.0f, 2.0f*M_PI); // Upper limit
           25   cout << "Integration path: b-a = " << b-a << '\n';
           26   Inttype n_eqs = 2; // Number of equations in ODE system
           27   vector<complex<Floattype> > y_start(n_eqs);
           28   complex<Floattype> y0(0.0f, 0.0f);
           29   complex<Floattype> y1(1.0f, 1.0f);
           30   y_start[0] = y0;
           31   y_start[1] = y1;
           32   Floattype h_start = 0.01f;
           33   ODE imagode(func1,        // ODE system
           34                     y_start,        // Initial values
           35               a,        // Lower limit
           36               b,        // Upper limit
           37               h_start,        // Start value of step size
           38               10000,        // Max. number of steps
           39               eps_machine*1e12f,  // Absolute precision
           40               eps_machine*1e12f); // Relative precision
           41   imagode.write("funcB.dat"); // Write solutions to data file
           42 
           43   // Report to stdout
           44   cout << "ODE system solved in "
           45        << imagode.steps() << " steps.\n\n";
           46 
           47   // Return successfully
           48   return 0;
           49 }
           50