MATLAB BUILDER JA 2 Podręcznik Użytkownika Strona 250

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 292
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 249
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
Przeglądanie stron 249
1 2 ... 245 246 247 248 249 250 251 252 253 254 255 ... 291 292

Komentarze do niniejszej Instrukcji

Brak uwag