Using the IMSL C Library for UNIX/Linux
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
Copy the following text into an editor and save the file as cnl.c.
/* Program start */
/* The header file for Mathematics of the IMSL C Library. */
/* For Statistics, use <imsl.h>>. */
#include <imsl.h>
main()
{
/* 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 and 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);
}
/* Program end */
2. Compiling and running the program
>> Running a program using the IMSL C Library for UNIX/Linux