Getting Started with the IMSL Numerical Libraries for C on Windows


Using the IMSL C Library for Windows

1. Creating a program
This simple example program will solve the following system of linear equations:
33x + 16y + 72z = 129
-24x - 10y - 57z = -96
18x - 11y + 7z = 8.5

2. Start a new project
Start Visual Studio and create a new Visual C++ Win32 Console Project named cnl.

3. Add the code
Copy the following text into the cnl.cpp source file and save it.


/* Program start */
/* The header file for Mathematics of the IMSL C Library. */
/* For Statistics, use <imsl.h>. */
#include "stdafx.h"
#include <imsl.h> 

int _tmain(int argc, _TCHAR* argv[])
{
    /* variable declaration */   
    int n = 3;
    float *x;
    static float a[] = {33.0, 16.0, 72.0,
                        -24.0, -10.0, -57.0,
                        18.0, -11.0, 7.0};
    static float b[] = {129.0, -96.0, 8.5};
    float *p_inva;

    /* The main IMSL function call to solve for x in Ax=B.
     * This is the floating point version, to use
     * double-precision arguments, call 
     * imsl_d_lin_sol_gen */
    x = imsl_f_lin_sol_gen(n, a, b, 0);

    /* Optional arguments are included after required 
     * arguments. These are usually preceded by a constant 
     * named IMSL_* indicating which optional argument is 
     * being passed.In this example, we request the inverse 
     * of the a matrix */
    x = imsl_f_lin_sol_gen (n, a, b,
          IMSL_INVERSE, &p_inva,
          0); 

	/* Print the solution x and the inverse of a using 
     * write_matrix, a printing utility */
    imsl_f_write_matrix ("Solution x", 1, n, x, 0);
    imsl_f_write_matrix ("Inverse of A", n, n, p_inva, 0);
    return 0;
} 
/* Program end */

4. Compiling and running the program
>> Running a program using the IMSL C Library for Windows


Company Products & Services Solutions Success Stories Support Downloads Email this page
© Copyright 2008 Visual Numerics, Inc. All Rights Reserved Legal Privacy