Wednesday, December 3, 2008

GSL 1.11 and .NET VC++ 2008



Well, I could not sleep tonight with thoughts of France on my mind and fighting flu symptoms so I thought I would run an example Visual Studio 2008 C++ with GSL. After some trial and error, I went to the site of David Geldreich


and downloaded his 1.11 version binaries for Windows and made the changes suggested by his
ReadMe document which I quote here:

"...Settings you have to change when creating your own project :

- additional include directory should point to gsl\include
- additional library directory should point to gsl\lib
- Code generation : use /MDd for Debug and /MD for Release
- Debug config should link with "cblas_d.lib gsl_d.lib"
- Release config should link with "cblas.lib gsl.lib"..."

His example code for solving a linear equation with matrix decompositions is reproduced here that I got to compile, link and run in VC++ 2008 Express.

#include
#include
////////////////////////////////////////////////////////////
// Solve Ax = b with LU and cholesky
int main(int argc, char **argv)
{
printf("=========== tst2 ===========\n");
double a_data[] = { 2,1,1,3,2,
1,2,2,1,1,
1,2,9,1,5,
3,1,1,7,1,
2,1,5,1,8 };
double b_data[] = { -2,4,3,-5,1 };
gsl_vector *x = gsl_vector_alloc (5);
gsl_permutation * p = gsl_permutation_alloc (5);
gsl_matrix_view m = gsl_matrix_view_array(a_data, 5, 5);
gsl_vector_view b= gsl_vector_view_array(b_data, 5);
int s;
gsl_linalg_LU_decomp (&m.matrix, p, &s);
gsl_linalg_LU_solve (&m.matrix, p, &b.vector, x);
printf ("x = \n");
gsl_vector_fprintf(stdout, x, "%g");
double a2_data[] = { 2,1,1,3,2,
1,2,2,1,1,
1,2,9,1,5,
3,1,1,7,1,
2,1,5,1,8 };
double b2_data[] = { -2,4,3,-5,1 };
gsl_matrix_view m2 = gsl_matrix_view_array(a2_data, 5, 5);
gsl_vector_view b2 = gsl_vector_view_array(b2_data, 5);
gsl_linalg_cholesky_decomp(&m2.matrix);
gsl_linalg_cholesky_solve(&m2.matrix, &b2.vector, x);
printf ("x = \n");
gsl_vector_fprintf(stdout, x, "%g");
gsl_permutation_free (p);
gsl_vector_free(x);
system("pause");
}

Now that I have a simple gsl example working, I can look at the stochastic volatility architecture and source code presented by Anthony Brockwell and write a prototype. Thanks David for making these binaries and code available for download. Success always makes one feel a little better.

No comments: