|
GRASS Programmer's Manual
6.5.svn(2012)-r51648
|
00001 #if defined(HAVE_CCMATH) 00002 #include <ccmath.h> 00003 #else 00004 #include <grass/ccmath_grass.h> 00005 #endif 00006 00163 int G_math_solv(double **a,double *b,int n) 00164 { 00165 return solv(a[0],b, n); 00166 } 00167 00168 00177 int G_math_solvps(double **a,double *b,int n) 00178 { 00179 return solvps(a[0], b,n); 00180 } 00181 00182 00193 void G_math_solvtd(double *a,double *b,double *c,double *x,int m) 00194 { 00195 solvtd(a, b, c, x, m); 00196 return; 00197 } 00198 00199 00200 /* 00201 \brief Solve an upper right triangular linear system T*x = b. 00202 00203 \param a = pointer to array of upper right triangular matrix T 00204 \param b = pointer to array of system vector The computation overloads this with the solution vector x. 00205 \param n = dimension (dim(a)=n*n,dim(b)=n) 00206 \return value: f = status flag, with 0 -> normal exit, -1 -> system singular 00207 */ 00208 int G_math_solvru(double **a,double *b,int n) 00209 { 00210 return solvru(a[0], b, n); 00211 } 00212 00213 00221 int G_math_minv(double **a,int n) 00222 { 00223 return minv(a[0], n); 00224 } 00225 00226 00235 int G_math_psinv(double **a,int n) 00236 { 00237 return psinv( a[0], n); 00238 } 00239 00240 00248 int G_math_ruinv(double **a,int n) 00249 { 00250 return ruinv(a[0], n); 00251 } 00252 00253 00254 /* 00255 ----------------------------------------------------------------------------- 00256 00257 Symmetric Eigensystem Analysis: 00258 ----------------------------------------------------------------------------- 00259 */ 00268 void G_math_eigval(double **a,double *ev,int n) 00269 { 00270 eigval(a[0], ev, n); 00271 return; 00272 } 00273 00274 00289 void G_math_eigen(double **a,double *ev,int n) 00290 { 00291 eigen(a[0], ev, n); 00292 return; 00293 } 00294 00295 00296 /* 00297 \brief Compute the maximum (absolute) eigenvalue and corresponding eigenvector of a real symmetric matrix A. 00298 00299 00300 \param a = array containing symmetric input matrix A 00301 \param u = array containing the n components of the eigenvector at exit (vector normalized to 1) 00302 \param n = dimension of system 00303 \return: ev = eigenvalue of A with maximum absolute value HUGE -> convergence failure 00304 */ 00305 double G_math_evmax(double **a,double *u,int n) 00306 { 00307 return evmax(a[0], u, n); 00308 } 00309 00310 00311 /* 00312 ------------------------------------------------------------------------------ 00313 00314 Singular Value Decomposition: 00315 ------------------------------------------------------------------------------ 00316 00317 A number of versions of the Singular Value Decomposition (SVD) 00318 are implemented in the library. They support the efficient 00319 computation of this important factorization for a real m by n 00320 matrix A. The general form of the SVD is 00321 00322 A = U*S*V~ with S = | D | 00323 | 0 | 00324 00325 where U is an m by m orthogonal matrix, V is an n by n orthogonal matrix, 00326 D is the n by n diagonal matrix of singular value, and S is the singular 00327 m by n matrix produced by the transformation. 00328 00329 The singular values computed by these functions provide important 00330 information on the rank of the matrix A, and on several matrix 00331 norms of A. The number of non-zero singular values d[i] in D 00332 equal to the rank of A. The two norm of A is 00333 00334 ||A|| = max(d[i]) , and the condition number is 00335 00336 k(A) = max(d[i])/min(d[i]) . 00337 00338 The Frobenius norm of the matrix A is 00339 00340 Fn(A) = Sum(i=0 to n-1) d[i]^2 . 00341 00342 Singular values consistent with zero are easily recognized, since 00343 the decomposition algorithms have excellent numerical stability. 00344 The value of a 'zero' d[i] is no larger than a few times the 00345 computational rounding error e. 00346 00347 The matrix U1 is formed from the first n orthonormal column vectors 00348 of U. U1[i,j] = U[i,j] for i = 1 to m and j = 1 to n. A singular 00349 value decomposition of A can also be expressed in terms of the m by\ 00350 n matrix U1, with 00351 00352 A = U1*D*V~ . 00353 00354 SVD functions with three forms of output are provided. The first 00355 form computes only the singular values, while the second computes 00356 the singular values and the U and V orthogonal transformation 00357 matrices. The third form of output computes singular values, the 00358 V matrix, and saves space by overloading the input array with 00359 the U1 matrix. 00360 00361 Two forms of decomposition algorithm are available for each of the 00362 three output types. One is computationally efficient when m ~ n. 00363 The second, distinguished by the prefix 'sv2' in the function name, 00364 employs a two stage Householder reduction to accelerate computation 00365 when m substantially exceeds n. Use of functions of the second form 00366 is recommended for m > 2n. 00367 00368 Singular value output from each of the six SVD functions satisfies 00369 00370 d[i] >= 0 for i = 0 to n-1. 00371 ------------------------------------------------------------------------------- 00372 */ 00373 00374 00386 int G_math_svdval(double *d,double **a,int m,int n) 00387 { 00388 return svdval(d, a[0], m, n); 00389 } 00390 00391 00402 int G_math_sv2val(double *d,double **a,int m,int n) 00403 { 00404 return sv2val(d, a[0], m, n); 00405 } 00406 00407 00408 /* 00409 \brief Compute the singular value transformation S = U~*A*V. 00410 00411 \param d = pointer to double array of dimension n (output = singular values of A) 00412 \param a = pointer to store of the m by n input matrix A (A is altered by the computation) 00413 \param u = pointer to store for m by m orthogonal matrix U 00414 \param v = pointer to store for n by n orthogonal matrix V 00415 \param m = number of rows in A 00416 \param n = number of columns in A (m>=n required) 00417 \return value: status flag with: 0 -> success -1 -> input error m < n 00418 */ 00419 int G_math_svduv(double *d,double **a,double **u,int m,double **v,int n) 00420 { 00421 return svduv(d, a[0], u[0], m, v[0], n); 00422 } 00423 00424 00436 int G_math_sv2uv(double *d,double **a,double **u,int m,double **v,int n) 00437 { 00438 return sv2uv(d, a[0], u[0], m, v[0], n); 00439 } 00440 00441 00455 int G_math_svdu1v(double *d,double **a,int m,double **v,int n) 00456 { 00457 return svdu1v(d, a[0], m, v[0], n); 00458 }