001 package numal.highprecision.test; 002 003 import java.text.DecimalFormat; 004 import numal.highprecision.*; 005 006 /** Compute the singular value decomposition of the 6x5 matrix A for which a[i][j]=1/*(i+j-1). 007 * For a successful test the main() method must output the following values : 008 *{ @code 009 Number of singular values not found : 0 010 011 Infinity norm : 2.28333E0 012 Max neglected subdiagonal element : 2.11719E-5 013 Number of iterations : 3 014 Numerical rank : 5 015 016 Singular values : 017 1.59212E0 018 2.24496E-1 019 1.36102E-2 020 1.25733E-4 021 1.41703E-5 022 023 Matrix U, first 3 columns : 024 -7.54979E-1 6.10111E-1 -2.33268E-1 025 -4.39093E-1 -2.26021E-1 7.05899E-1 026 -3.17031E-1 -3.73070E-1 2.11269E-1 027 -2.49995E-1 -3.95578E-1 -1.47776E-1 028 -2.07050E-1 -3.84833E-1 -3.68054E-1 029 -1.76997E-1 -3.64582E-1 -4.95335E-1 030 Last 2 columns : 031 9.87458E-3 -2.57541E-2 032 -6.88740E-3 2.67620E-1 033 -3.89435E-1 -5.02005E-1 034 8.52031E-1 -1.34877E-1 035 -2.25331E-1 7.40444E-1 036 -2.67328E-1 -3.30543E-1 037 } 038 * 039 */ 040 public class Test_qrisngvaldec extends Object { 041 042 public static void main(String args[]) { 043 044 int i,j; 045 double val[] = new double[6]; 046 double em[] = new double[8]; 047 double a[][] = new double[7][6]; 048 double v[][] = new double[6][6]; 049 050 for (i=1; i<=6; i++) 051 for (j=1; j<=5; j++) a[i][j]=1.0/(i+j-1); 052 em[0]=1.0e-6; em[2]=1.0e-5; em[4]=25.0; em[6]=1.0e-5; 053 i=Linear_algebra.qrisngvaldec(a,6,5,val,v,em); 054 DecimalFormat fiveDigit = new DecimalFormat("0.00000E0"); 055 System.out.println("Number of singular values not found : " + 056 i + "\n\nInfinity norm : " + fiveDigit.format(em[1]) + 057 "\nMax neglected subdiagonal element : " + 058 fiveDigit.format(em[3]) + 059 "\nNumber of iterations : " + (int)em[5] + 060 "\nNumerical rank : " + (int)em[7] + 061 "\n\nSingular values :"); 062 for (i=1; i<=5; i++) 063 System.out.println(" " + fiveDigit.format(val[i])); 064 System.out.println("\nMatrix U, first 3 columns :"); 065 for (i=1; i<=6; i++) 066 System.out.println(" " + 067 fiveDigit.format(a[i][1]) + "\t" + 068 fiveDigit.format(a[i][2]) + "\t" + 069 fiveDigit.format(a[i][3])); 070 System.out.println("Last 2 columns :"); 071 for (i=1; i<=6; i++) 072 System.out.println(" " + 073 fiveDigit.format(a[i][4]) + "\t" + 074 fiveDigit.format(a[i][5])); 075 } 076 }