Changeset 7101
- Timestamp:
- May 9, 2006, 2:48:50 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psMatrix.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psMatrix.c
r4589 r7101 21 21 * @author Robert DeSonia, MHPCC 22 22 * 23 * @version $Revision: 1.3 6$ $Name: not supported by cvs2svn $24 * @date $Date: 200 5-07-21 01:40:10 $23 * @version $Revision: 1.37 $ $Name: not supported by cvs2svn $ 24 * @date $Date: 2006-05-10 00:48:50 $ 25 25 * 26 26 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 44 44 #include "psConstants.h" 45 45 #include "psErrorText.h" 46 46 #include "psTrace.h" 47 47 48 48 /*****************************************************************************/ … … 304 304 305 305 return out; 306 } 307 308 // This is a temporary gauss-jordan solver based on gene's 309 // version based on the Numerical Recipes version 310 bool psMatrixGJSolve( 311 psImage *a, 312 psVector *b) 313 { 314 int *indxc,*indxr,*ipiv; 315 int icol, irow; 316 int i, j, k, l, ll; 317 float big, dum, pivinv; 318 psF64 *vector = b->data.F64; 319 psF64 **matrix = a->data.F64; 320 321 int Nx = a->numCols; 322 323 indxc = psAlloc(Nx*sizeof(int)); 324 indxr = psAlloc(Nx*sizeof(int)); 325 ipiv = psAlloc(Nx*sizeof(int)); 326 for (j = 0; j < Nx; j++) { 327 ipiv[j] = 0; 328 } 329 330 irow = icol = 0; 331 big = fabs(matrix[0][0]); 332 333 for (i = 0; i < Nx; i++) { 334 big = 0.0; 335 for (j = 0; j < Nx; j++) { 336 if (!isfinite(matrix[i][j])) { 337 psTrace (__func__, 3, "Input matrix contains NaNs: matrix[%d][%d] is %.2f\n", i, j, matrix[i][j]); 338 goto fescape; 339 } 340 if (ipiv[j] != 1) { 341 for (k = 0; k < Nx; k++) { 342 if (ipiv[k] == 0) { 343 if (fabs (matrix[j][k]) >= big) { 344 big = fabs(matrix[j][k]); 345 irow = j; 346 icol = k; 347 } 348 } else { 349 if (ipiv[k] > 1) { 350 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Singular Matrix (1).\n"); 351 goto fescape; 352 } 353 } 354 } 355 } 356 } 357 ipiv[icol]++; 358 if (irow != icol) { 359 for (l = 0; l < Nx; l++) { 360 PS_SWAP(matrix[irow][l], matrix[icol][l]); 361 } 362 PS_SWAP(vector[irow], vector[icol]); 363 } 364 indxr[i] = irow; 365 indxc[i] = icol; 366 if (matrix[icol][icol] == 0.0) { 367 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Singular Matrix (2).\n"); 368 goto fescape; 369 } 370 pivinv = 1.0 / matrix[icol][icol]; 371 matrix[icol][icol] = 1.0; 372 for (l = 0; l < Nx; l++) { 373 matrix[icol][l] *= pivinv; 374 } 375 vector[icol] *= pivinv; 376 377 for (ll = 0; ll < Nx; ll++) { 378 if (ll != icol) { 379 dum = matrix[ll][icol]; 380 matrix[ll][icol] = 0.0; 381 for (l = 0; l < Nx; l++) { 382 matrix[ll][l] -= matrix[icol][l]*dum; 383 } 384 vector[ll] -= vector[icol]*dum; 385 } 386 } 387 } 388 389 for (l = Nx - 1; l >= 0; l--) { 390 if (indxr[l] != indxc[l]) { 391 for (k = 0; k < Nx; k++) { 392 PS_SWAP(matrix[k][indxr[l]], matrix[k][indxc[l]]); 393 } 394 } 395 } 396 psFree(ipiv); 397 psFree(indxr); 398 psFree(indxc); 399 return true; 400 401 fescape: 402 psFree(ipiv); 403 psFree(indxr); 404 psFree(indxc); 405 return false; 306 406 } 307 407
Note:
See TracChangeset
for help on using the changeset viewer.
