1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
|
/*
This file is part of the FElt finite element analysis package.
Copyright (C) 1993-2000 Jason I. Gobat and Darren C. Atkinson
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/************************************************************************
* File: matrix.h
*
* Description:
************************************************************************/
# ifndef _MATRIX_H
# define _MATRIX_H
# include <stdio.h> /* for FILE definition */
# include "status.h"
# include "proto.h"
typedef struct matrix *Matrix;
struct matrix {
unsigned nrows; /* number of rows */
unsigned ncols; /* number of columns */
double **data; /* matrix data */
unsigned *diag; /* diagonal addresses for compact column */
unsigned size; /* actual size of compact storage */
unsigned refcount; /* count of children */
Matrix parent; /* parent of possible subsection */
};
# define Mrows(m) ((m) -> nrows)
# define Mcols(m) ((m) -> ncols)
# define Msize(m) ((m) -> size ? (m) -> size : Mrows(m) * Mcols(m))
# define IsFull(m) (!(m) -> size)
# define IsCompact(m) ((m) -> size)
# define IsSquare(m) (Mrows(m) == Mcols(m))
# define IsRowVector(m) (Mrows(m) == 1)
# define IsColumnVector(m) (Mcols(m) == 1)
# define IsSubsection(m) ((m) -> parent == NULL ? 0 : 1)
# define sdata(m,i,j) ((m) -> data [(i)][(j)])
/*
* for backward compatibility with the old matrix routines
*/
typedef Matrix Vector;
# define MatrixData(m) ((m) -> data)
# define VectorData(m) ((m) -> data [1])
# define MatrixRows(m) ((m) -> nrows)
# define MatrixCols(m) ((m) -> ncols)
# define VectorSize(m) (IsColumnVector(m) ? (m) -> nrows : (m) -> ncols)
# define NullMatrix ((Matrix) NULL)
# define NullVector ((Matrix) NULL)
# define CreateMatrix CreateFullMatrix
# define CreateVector CreateColumnVector
# define DestroyVector DestroyMatrix
/*
* prototypes for DATA manipulation routines
*/
double mdata PROTO ((
Matrix, /* matrix to fetch data from */
unsigned, /* row index */
unsigned /* column index */
));
Matrix CreateSubsectionMatrix PROTO ((
Matrix, /* matrix to subsection */
unsigned, /* starting row */
unsigned, /* starting column */
unsigned, /* ending row */
unsigned /* ending column */
));
Matrix CreateFullMatrix PROTO ((
unsigned, /* number of rows */
unsigned /* number of columns */
));
Matrix CreateRowVector PROTO ((
unsigned /* vector length */
));
Matrix CreateColumnVector PROTO ((
unsigned /* vector length */
));
void DestroyMatrix PROTO ((
Matrix /* matrix to free */
));
Matrix CreateCompactMatrix PROTO ((
unsigned, /* number of rows */
unsigned, /* number of columns */
unsigned, /* actual size of storage */
unsigned * /* diagonal index array */
));
Matrix CreateCopyMatrix PROTO ((
Matrix /* matrix to copy data from */
));
Matrix MakeFullFromCompact PROTO ((
Matrix /* compact matrix to expand */
));
Matrix MakeCompactFromFull PROTO ((
Matrix /* full matrix to compact */
));
int ConvertRowColumn PROTO ((
unsigned, /* row index */
unsigned, /* column index */
Matrix /* compact matrix */
));
/*
* prototypes for the BASIC matrix routines
*/
int ZeroMatrix PROTO (( /* a = 0 */
Matrix /* matrix to fill with zeros */
));
int CopyMatrix PROTO (( /* b = a */
Matrix, /* source matrix */
Matrix /* destination matrix */
));
int IdentityMatrix PROTO (( /* a = [I] */
Matrix /* destination matrix for identity */
));
int RandomMatrix PROTO (( /* a(i,j) = rand() */
Matrix, /* matrix to randomize */
int /* optional seed */
));
int MirrorMatrix PROTO ((
Matrix /* matrix to complete */
));
int MultiplyMatrices PROTO (( /* c = ab */
Matrix, /* destination matrix */
Matrix, /* source matrix 1 */
Matrix /* source matrix 2 */
));
int AddMatrices PROTO (( /* c = a + b */
Matrix, /* destination matrix */
Matrix, /* source matrix 1 */
Matrix /* source matrix 2 */
));
int SubtractMatrices PROTO (( /* c = a - b */
Matrix, /* destination matrix */
Matrix, /* source matrix 1 */
Matrix /* source matrix 2 */
));
int ModMatrices PROTO (( /* c = a % b */
Matrix, /* destination matrix */
Matrix, /* source matrix 1 */
Matrix /* source matrix 2 */
));
int Saxpy PROTO (( /* c = b + alpha*a */
Matrix, /* destination vector */
Matrix, /* source 1 vector */
Matrix, /* source 2 vector */
double /* scale factor */
));
int Gaxpy PROTO (( /* c = b + Aa */
Matrix, /* destination vector */
Matrix, /* source 1 vector */
Matrix, /* source 2 vector */
Matrix /* source matrix */
));
int ScaleMatrix PROTO (( /* b(i,j) = factor*a(i,j) + offset */
Matrix, /* destination matrix */
Matrix, /* source matrix */
double, /* multiplicative scale factor */
double /* additive offset */
));
int SqrtMatrix PROTO (( /* b(i,j) = sqrt (a(i,j)) */
Matrix, /* destination matrix */
Matrix /* source matrix */
));
int DotBProduct PROTO (( /* x = aTb */
double *, /* pointer to result location */
Matrix, /* source vector (row) 1 */
Matrix /* source vector 2 */
));
int TransposeMatrix PROTO (( /* b = aT */
Matrix, /* destination matrix */
Matrix /* source matrix */
));
int CompareEQMatrices PROTO (( /* c = (a == b) */
Matrix, /* destination matrix */
Matrix, /* first RHS matrix */
Matrix /* second RHS matrix */
));
int CompareNEQMatrices PROTO (( /* c = (a != b) */
Matrix, /* destination matrix */
Matrix, /* first RHS matrix */
Matrix /* second RHS matrix */
));
int CompareGTMatrices PROTO (( /* c = (a > b) */
Matrix, /* destination matrix */
Matrix, /* first RHS matrix */
Matrix /* second RHS matrix */
));
int CompareLTMatrices PROTO (( /* c = (a < b) */
Matrix, /* destination matrix */
Matrix, /* first RHS matrix */
Matrix /* second RHS matrix */
));
int CompareLTEMatrices PROTO (( /* c = (a <= b) */
Matrix, /* destination matrix */
Matrix, /* first RHS matrix */
Matrix /* second RHS matrix */
));
int CompareGTEMatrices PROTO (( /* c = (a >= b) */
Matrix, /* destination matrix */
Matrix, /* first RHS matrix */
Matrix /* second RHS matrix */
));
int PrintMatrix PROTO (( /* print matrix m to file fp */
Matrix, /* matrix to print */
FILE * /* file pointer for output */
));
int PrintMatrixSubsection PROTO (( /* print matrix m to file fp */
Matrix, /* matrix to print */
unsigned, /* starting row */
unsigned, /* starting column */
unsigned, /* ending row */
unsigned, /* ending column */
FILE * /* file pointer for output */
));
/*
* protoypes for the FACTORization machine
*/
int QRFactorMatrix PROTO (( /* factor a such that qTa = r */
Matrix, /* destination matrix for q */
Matrix, /* destination matrix for r */
Matrix /* source matrix */
));
int CholeskyFactorMatrix PROTO (( /* factor a such that bbT=a */
Matrix, /* destination matrix */
Matrix /* source matrix */
));
int InvertMatrix PROTO (( /* compute b = inv(a) where a is LU factored */
Matrix, /* destination matrix */
Matrix, /* factored source matrix */
Matrix /* pivot vector */
));
int DeterminantMatrix PROTO (( /* result = |a| */
double *, /* pointer to result location */
Matrix, /* factorized source matrix */
Matrix /* pivot vector */
));
int LUFactorMatrix PROTO (( /* factor a into LU and store in b */
Matrix, /* destination matrix */
Matrix, /* source matrix */
Matrix, /* permutation vector */
int * /* singularity code */
));
int LUBackSolveMatrix PROTO (( /* solve Ax=b and store result in c */
Matrix, /* destination vector */
Matrix, /* factorized source matrix */
Matrix, /* right hand side vector */
Matrix /* pivot vector */
));
int FormLUPMatrices PROTO (( /* separate matrices from factors */
Matrix, /* return matrix for L */
Matrix, /* return matrix for U */
Matrix, /* return matrix for P */
Matrix, /* factored form of matrix */
Matrix /* pivot vector */
));
int CroutFactorMatrix PROTO (( /* Crout factorize A and store in A */
Matrix /* source and destination matrix */
));
int CroutBackSolveMatrix PROTO (( /* solve Ax=b and store x in b */
Matrix, /* Crout factored LHS matrix */
Matrix /* RHS (and dest) vector */
));
/*
* prototypes for the EIGEN routines
*/
int GeneralMatrixEigenModes PROTO (( /* full, non-symmetric matrix */
Matrix, /* input matrix */
Matrix, /* output vector of eigenvalues */
double, /* convergence tolerance */
unsigned /* limiting number of iterations */
));
int TridiagSymmMatrixEigenModes PROTO ((
Matrix, /* vector of diagonal elements */
Matrix, /* vector of sub-diag elements */
Matrix, /* vector of eigenvalues */
Matrix, /* eigenvectors output */
unsigned /* iteration limit */
));
int SymmetricMatrixEigenModes PROTO ((
Matrix, /* source matrix */
Matrix, /* vector for eigenvalues */
Matrix, /* matrix for eigenvectors */
unsigned /* iteration limit */
));
int BuildTridiagonalVectors PROTO ((
Matrix, /* symmetric, tri-diagonal input */
Matrix, /* output vector of diag elements */
Matrix /* vector of sub-digaonal elements */
));
int NormalizeByMaximum PROTO ((
Matrix, /* destination matrix */
Matrix, /* eigenvectors to normalize */
unsigned /* flag to preserve sign */
));
int NormalizeByFirst PROTO ((
Matrix, /* destination matrix */
Matrix /* eigenvectors to normalize */
));
int NormalizeByLength PROTO ((
Matrix, /* destination matrix */
Matrix /* eigenvectors to normalize */
));
int TridiagonalReduction PROTO ((
Matrix, /* source matrix */
Matrix, /* dest vector for diag elements */
Matrix, /* dest vector for sub-diag elements */
Matrix /* accumulated orthog. transforms */
));
/*
* prototypes for the NORM routines
*/
int FrobeniusNormMatrix PROTO (( /* result = ||a||_f */
double *, /* pointer to result location */
Matrix /* matrix to take norm of */
));
int PNormMatrix PROTO (( /* result = ||a||_p */
double *, /* pointer to space for result */
Matrix, /* source matrix */
char * /* "1", "inf" type of norm */
));
int PNormVector PROTO (( /* result = ||a||_p */
double *, /* pointer to space for result */
Matrix, /* source vector */
char * /* "1", "2", "inf" type of norm */
));
/*
* prototypes for the PROPERTY routines
*/
int IsSymmetricMatrix PROTO ((
Matrix
));
int IsZeroMatrix PROTO ((
Matrix
));
/*
* prototypes for the STATISTICS routines
*/
int MaximumMatrix PROTO ((
Matrix,
double *
));
int MinimumMatrix PROTO ((
Matrix,
double *
));
int SumMatrix PROTO ((
Matrix,
double *
));
int MeanMatrix PROTO ((
Matrix,
double *
));
int StddevMatrix PROTO ((
Matrix,
double *
));
/*
* prototypes for the IO routines
*/
int MatrixToMatlab PROTO ((
Matrix,
FILE *,
char *
));
int MatricesToMatlab PROTO ((
Matrix *,
unsigned,
FILE *,
char **
));
Matrix MatlabToMatrix PROTO ((
FILE *
));
/*
* prototypes for the SOLVER routines
*/
int GaussSeidel PROTO ((
Matrix,
Matrix,
Matrix
));
# endif /* _MATRIX_H */
|