Getting Started with the JMSL Numerical Library for Java


Using the JMSL Numerical Library for Java

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 Jmsl.java.


/* Program start */
// The Mathematics package for the JMSL Numerical Library for Java.
// For Statistics, use com.imsl.stat.*
import com.imsl.math.*;

public class Jmsl {
    public static void main(string args[]) 
        throws SingularMatrixException{
    // variable declaration   
    double a[][] = {{33.0, 16.0, 72.0},
                    {-24.0, -10.0, -57.0},
                    {18.0, -11.0, 7.0}};
    double b[] = {129.0, -96.0, 8.5};
    double x[];
    double ainv[][];

    // The main JMSL function call to solve for x in Ax=B.
    // In Java, the LU object first has to be instantiated.
    LU lu = new LU(a);
    // Then we can call the solve method.
    x = lu.solve(b);

    // Optional outputs are obtained using other method 
    // calls. In this example, we request the inverse 
    // of the a matrix
    ainv = lu.inverse(); 

    // Write the solution x and the inverse of a using 
    // PrintMatrix class, a printing utility */
    new PrintMatrix("Solution x").print(x);
    new PrintMatrix("Inverse of A").print(ainv);
    }
} 
/* Program end */

2. Compiling and running the program
>> Running a program using the JMSL Numerical Library for Java


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