0

Normal distribution in BOOST

Posted by Derek Jing on 1:46 PM in ,
#include <boost/math/distributions/normal.hpp> // for normal_distribution
using boost::math::normal; // typedef provides default type is double.

#include <iostream>
using std::cout; using std::endl; using std::left; using std::showpoint; using std::noshowpoint;

#include <iomanip>
using std::setw; using std::setprecision;

#include <limits>
using std::numeric_limits;

int main()
{
// Generate a normal random number
normal s; // (default mean = zero, and standard deviation = unity)
cout << "Standard normal distribution, mean = "<< s.mean()
<< ", standard deviation = " << s.standard_deviation() << endl;

// Calculate PDF
cout << "Probability distribution function values" << endl;
cout << " z  pdf " << endl;
cout.precision(5);
for (double z = -10; z < 10; z+= 1) 
{
cout << left << setprecision(3) << setw(6) << z << " "
<< setprecision(17) << setw(12) << pdf(s, z) << endl;
}
cout.precision(6); // default


// Calculate CDF
cout << "Integral (area under the curve) from - infinity up to z " << endl;
cout << " z   cdf " << endl;
for (double z = -5; z < 5; z+= 1)
{
cout << left << setprecision(3) << setw(6) << z << " "
<< setprecision(17) << setw(12) << cdf(s, z) << endl;
}
cout.precision(6); // default


// Calculate quantile
cout << "95% of area has a z below " << quantile(s, 0.95) << endl;

return 0;
}

0

Getting started with Boost under Windows

Posted by Derek Jing on 2:21 PM in ,
  • Download installer binary from Boostpro Computing and install.

  • To build from Visual Studio IDE
    Setting up #include paths in Microsoft Visual Studio
    Right click the project name in the solution explorer > Properties > C/C++ > General > Additional Include Directories, enter the path to the Boost root directory, for example
    C:\Program Files\boost\boost_1_42

    In C++ code, include something like
    #include <boost/lambda.hpp>

  • To link from within Visual Studio IDE
    Right click the project name in the solution explorer > Properties > Linker > General > Additional Library Directories, enter the path to the Boost root directory, for example
    C:\Program Files\boost\boost_1_42\lib\


0

Automatically generate PDF navigating bookmarks in LaTex

Posted by Derek Jing on 9:09 AM in
 \usepackage[colorlinks=true, pdfstartview=FitV, linkcolor=blue,
citecolor=blue, urlcolor=blue]{hyperref}

Copyright © 2009 Derek's Technical Notes All rights reserved.