5 Sample Applications (Java)
if (n <= 0)
{
System.out.println("Error: must input a positive integer");
return;
}
/*
* Allocate matrix. If second input is "sparse"
* allocate a sparse array
*/
int[] dims = {n, n};
if (args.length > 1 && args[1].equals("sparse"))
a = MWNumericArray.newSparse(dims[0], dims[1],n+2*(n-1), MWClassID.DOUBLE, MWComplexity.REAL);
else
a = MWNumericArray.newInstance(dims,MWClassID.DOUBLE, MWComplexity.REAL);
/* Set matrix values */
int[] index = {1, 1};
for (index[0] = 1; index[0] <= dims[0]; index[0]++)
{
for (index[1] = 1; index[1] <= dims[1]; index[1]++)
{
if (index[1] == index[0])
a.set(index, 2.0);
else if (index[1] == index[0]+1 || index[1] == index[0]-1)
a.set(index, -1.0);
}
}
/* Create new factor object */
theFactor = new factor();
/* Print original matrix */
System.out.println("Original matrix:");
System.out.println(a);
/* Compute cholesky factorization and print results. */
5-20
Komentarze do niniejszej Instrukcji