MRS  1.0
A C++ Class Library for Statistical Set Processing
Basic C-XSC Examples

To learn how to use the C-XSC class library and the GSL you can read the page Basic C-XSC Examples and follow the examples described there. For a proper introduction to C-XSC and the accompanying Toolbox with more sophisticated applications see the C-XSC Documentation.

On this page we will try to show you how to use the C-XSC class library with some short and simple examples.

Example 1 - Intervals in C-XSC

In the following simple program we use C-XSC intervals to do basic arithmetic operations and output the results:

#include "interval.hpp"  // include interval arithmetic in C-XSC
#include <iostream>      // include standard Input Output STREAM 
using namespace cxsc;    
using namespace std;

int main()
{
  interval a, b;            // Standard intervals     
  a = 1.0;                  // a   = [1.0,1.0]       
  "[1, 2]" >> b;          // string to interval conversion b   = [1.0,2.0]        
  cout << "a - a = " << a-a << endl;
  cout << "b - b = " << b-b << endl;
}

/* --------------------------- Output ------------------------------
$ ./example 
a - a = [ -0.000000,  0.000000]
b - b = [ -1.000000,  1.000000]
------------------------------------------------------------------*/

Let's start examining the code line by line. The first line:

#include "interval.hpp"  // include interval arithmetic in C-XSC

includes the basic interval class of C-XSC in the program. The second line:

#include <iostream>      // include standard Input Output STREAM 

includes the standard iostream library for basic input and output operations. The next two lines inform the compiler about C-XSC's namespace cxsc and the standard library namespace std. The namespace cxsc is where all of C-XSC's classes and methods are stored. This allows us to use C-XSC classes without having to fully qualify their identifiers.

using namespace cxsc;    
using namespace std;

Next we declare two interval variables and assign adequate values in the following lines.

  interval a, b;            // Standard intervals     
  a = 1.0;                  // a   = [1.0,1.0]       
  "[1, 2]" >> b;          // string to interval conversion b   = [1.0,2.0]        

Finally, we print out the result for our desired subtractions.

  cout << "a - a = " << a-a << endl;
  cout << "b - b = " << b-b << endl;

To compile the program we edit the Makefile in the examples directory. First we set the 'PROGRAM=example' and the PREFIX to the appropriate directory that contains the C-XSC includes and lib directories. Then we type 'make all' in a Unix system to compile the program.

Example 2 - Multi-precision Intervals in C-XSC

#include "l_interval.hpp"  // interval staggered arithmetic in C-XSC
#include <iostream>
using namespace cxsc;
using namespace std;

int main() 
{
  l_interval a, b;         // Multiple-precision intervals in C-XSC
  stagprec = 2;            // global integer variable      
  cout << SetDotPrecision(16*stagprec, 16*stagprec-3) << RndNext;
  // I/O for variables of type l_interval is done using
  // the long accumulator (i.e. a dotprecision variable)   

  a = 1.0;                  // a   = [1.0,1.0]       
  "[1, 2]" >> b;          // string to interval conversion b   = [1.0,2.0]        
  cout << "a - a = " << a-a << endl;
  cout << "b - b = " << b-b << endl;
  cout << "a/b = " << a/b << endl;  
}

/* --------------------------- Output ------------------------------
$ ./lexample 
a - a = [ 0.00000000000000000000000000000, 0.00000000000000000000000000000]
b - b = [-1.00000000000000000000000000000, 1.00000000000000000000000000000]
a/b = [ 0.50000000000000000000000000000, 1.00000000000000000000000000000]
------------------------------------------------------------------*/

Example 3 - Mean in GSL and Dot Precision Accumulators in C-XSC

Example 4 - Range Enclosure with Automatic Differentiation

Example 5 - Global Optimisation for Maximum Likelihood

 All Classes Namespaces Functions Variables Typedefs Enumerations Friends