/*************************************************************************/ /* */ /* Copyright (c) 1994 Stanford University */ /* */ /* All rights reserved. */ /* */ /* Permission is given to use, copy, and modify this software for any */ /* non-commercial purpose as long as this copyright notice is not */ /* removed. All other uses, including redistribution in whole or in */ /* part, are forbidden without prior written permission. */ /* */ /* This software is provided with absolutely no warranty and no */ /* support. */ /* */ /*************************************************************************/ EXTERN_ENV #include "matrix.h" #include #include double *TriBSolve(BMatrix LB, double *b, long *PERM) { long i, j, i1, j1, bl, row; double *y, *xp, *x, *bt; x = (double *) malloc(LB.n*sizeof(double)); xp = (double *) malloc(LB.n*sizeof(double)); y = (double *) malloc(LB.n*sizeof(double)); bt = (double *) malloc(LB.n*sizeof(double)); for (j=0; jnz[(j1-j)+(j1-j)*LB.entry[bl].block->length]; for (i1=j1-j+1; i1length; i1++) { if (LB.entry[bl].block->structure) row = LB.row[bl] + LB.entry[bl].block->structure[i1]; else row = LB.row[bl] + i1; bt[PERM[row]] -= LB.entry[bl].block->nz[ i1+(j1-j)*LB.entry[bl].block->length] * y[j1]; } } /* blocks below diagonal */ for (bl=LB.col[j]+1; bllength; i1++) { if (LB.entry[bl].block->structure) row = LB.row[bl] + LB.entry[bl].block->structure[i1]; else row = LB.row[bl] + i1; for (j1=j; j1nz[ i1+(j1-j)*LB.entry[bl].block->length] * y[j1]; } } } } } /* back solve */ j = LB.n-1; if (LB.partition_size[j] < 0) j += LB.partition_size[j]; while (j >= 0) { if (LB.domain[j]) { for (i=LB.col[j]+1; ilength; i1++) { if (LB.entry[bl].block->structure) row = LB.row[bl] + LB.entry[bl].block->structure[i1]; else row = LB.row[bl] + i1; for (j1=j; j1nz[ i1+(j1-j)*LB.entry[bl].block->length] * xp[row]; } } } /* diagonal block */ bl = LB.col[j]; for (j1=j+LB.partition_size[j]-1; j1>=j; j1--) { for (i1=j1-j+1; i1length; i1++) { if (LB.entry[bl].block->structure) row = LB.row[bl] + LB.entry[bl].block->structure[i1]; else row = LB.row[bl] + i1; y[j1] -= LB.entry[bl].block->nz[ i1+(j1-j)*LB.entry[bl].block->length] * xp[row]; } xp[j1] = y[j1]/ LB.entry[bl].block->nz[(j1-j)+(j1-j)*LB.entry[bl].block->length]; } } j--; if (j>=0 && LB.partition_size[j] < 0) j += LB.partition_size[j]; } for (j=0; j tmp) tmp = fabs(x[i]-1.0); return(tmp); } double *CreateVector(SMatrix M) { long i, j; double *b; b = NewVector(M.n); for (j=0; j