00001
00002 /*----------------------------------------------------------------------------
00003 E.S.O.
00004 -----------------------------------------------------------------------------
00005 File name : matrix.h
00006 Author : Nicolas Devillard
00007 Created on : 1994
00008 Hardware : Sun Sparc 20
00009 Software : ANSI C under Solaris Unix
00010 Part of ECLIPSE library for Adonis
00011 Description : basic 2d matrix handling routines
00012 ---------------------------------------------------------------------------*/
00013
00014 /*
00015
00016 $Id: matrix.h,v 1.1 2003/09/03 12:50:47 amodigli Exp $
00017 $Author: amodigli $
00018 $Date: 2003/09/03 12:50:47 $
00019 $Revision: 1.1 $
00020
00021 */
00022
00023 #ifndef _MATRIX_H_
00024 #define _MATRIX_H_
00025
00026
00027 /*----------------------------------------------------------------------------
00028 * Includes
00029 *--------------------------------------------------------------------------*/
00030
00031
00032 #include "memory.h"
00033
00034
00035 /*----------------------------------------------------------------------------
00036 * Defines
00037 *--------------------------------------------------------------------------*/
00038
00039 #define Nulmat NULL
00040 #define null_mx(m) ((m) == Nulmat)
00041 #define _(b,i,j) (*((b)->m+(i)*(b)->nc+(j))) /* b(i,j)*/
00042
00043
00044 /*----------------------------------------------------------------------------
00045 * New Types
00046 *--------------------------------------------------------------------------*/
00047
00048
00049 typedef struct _MATRIX_ {
00050 double *m;
00051 int nr;
00052 int nc;
00053 } mat, *Matrix;
00054
00055
00056
00057 /*----------------------------------------------------------------------------
00058 * Function ANSI C prototypes
00059 *--------------------------------------------------------------------------*/
00060
00061
00062 /*---------------------------------------------------------------------------
00063 * Function : create_mx()
00064 * In : number of rows, number of columns
00065 * Out : Matrix
00066 * Job : allocates memory for a matrix
00067 * Notice : returns Nulmat if cannot allocate
00068 *--------------------------------------------------------------------------*/
00069 Matrix
00070 create_mx(int nr, int nc) ;
00071
00072
00073 /*---------------------------------------------------------------------------
00074 * Function : copy_mx()
00075 * In : Matrix
00076 * Out : Matrix
00077 * Job : copy a matrix
00078 * Notice : returns Nulmat if cannot allocate
00079 *--------------------------------------------------------------------------*/
00080 Matrix
00081 copy_mx(Matrix a) ;
00082
00083
00084 /*---------------------------------------------------------------------------
00085 * Function : close_mx()
00086 * In : Matrix
00087 * Out : void
00088 * Job : free memory associated to a matrix
00089 * Notice :
00090 *--------------------------------------------------------------------------*/
00091 void
00092 close_mx(Matrix a) ;
00093
00094
00095 /*---------------------------------------------------------------------------
00096 * Function : mul_mx()
00097 * In : 2 Matrix
00098 * Out : Matrix
00099 * Job : Multiplies 2 Matrixes
00100 * Notice :
00101 *--------------------------------------------------------------------------*/
00102 Matrix
00103 mul_mx(Matrix a, Matrix b) ;
00104
00105
00106 /*---------------------------------------------------------------------------
00107 * Function : invert_mx()
00108 * In : (square) Matrix
00109 * Out : Matrix
00110 * Job : invert a matrix
00111 * Notice : Hardcoded for 1x1, 2x2, 3x3 matrices
00112 *--------------------------------------------------------------------------*/
00113 Matrix
00114 invert_mx(Matrix aa) ;
00115
00116
00117 /*---------------------------------------------------------------------------
00118 * Function : transp_mx()
00119 * In : Matrix
00120 * Out : Matrix
00121 * Job : transposition of a Matrix
00122 * Notice :
00123 *--------------------------------------------------------------------------*/
00124
00125 Matrix
00126 transp_mx(Matrix a) ;
00127
00128
00129 /*---------------------------------------------------------------------------
00130 * Function : gauss_pivot()
00131 * In : 2 matrix lines, number of rows in line
00132 * Out : error code: 1 if Ok, 0 else
00133 * Job : line simplification with Gauss method
00134 * Notice : should be private to invert_mx()
00135 *--------------------------------------------------------------------------*/
00136 int
00137 gauss_pivot(double *ptra, double *ptrc, int n) ;
00138
00139
00140 /*---------------------------------------------------------------------------
00141 Function : least_sq_mx()
00142 In : 2 matrices A, B
00143 Out : 1 matrix
00144 Job : from the set XA = B, compute the matrix P defined by
00145 P = B.tA.inv(A.tA)
00146 P solves X by a least-squares criterion
00147 Notice :
00148 ---------------------------------------------------------------------------*/
00149
00150 Matrix least_sq_mx(
00151 Matrix A,
00152 Matrix B
00153 ) ;
00154
00155
00156 /*---------------------------------------------------------------------------
00157 Function : print_mx()
00158 In : 1 (allocated) matrix. matrix name
00159 Out : matrix values on stdout
00160 Job : print out matrix values
00161 Notice :
00162 ---------------------------------------------------------------------------*/
00163
00164 void print_mx(
00165 Matrix M,
00166 char * name
00167 ) ;
00168
00169
00170 #endif
00171 /*--------------------------------------------------------------------------*/
1.2.13.1 written by Dimitri van Heesch,
© 1997-2001