35 Bmatrix() { m=n=0; clabel = rlabel = NULL; data = NULL; }
38 data =
new double[m*n];
39 for (
long i=0; i<m*n; i++ ) data[i] = 0;
40 clabel = rlabel = NULL;
44 data =
new double[m*n];
45 clabel = rlabel = NULL;
48 for ( i=0; i<m*n; i++ ) data[i] = 0;
50 for ( i=1; i<=m; i++ ) {
51 if ( cflag == 1 ) label =
Bstring(i,
"%d");
58 for ( i=1; i<=n; i++ ) {
59 if ( rflag == 1 ) label =
Bstring(i,
"%d");
68 if ( m != mat.n )
return mat_new;
71 for ( i=l=0; i<n; i++ )
72 for ( j=0; j<mat.m; j++, l++ )
73 for ( k=0; k<m; k++ ) mat_new.data[l] += data[i*m+k]*mat.data[k*mat.m+j];
76 double&
operator[](
long i) {
if ( i < 0 ) i = 0;
if ( i >= m*n ) i = m*n-1;
return data[i]; }
79 long size() {
return m*n; }
95 if ( m != n )
return(0);
96 double* mat =
new double [n*n];
97 for (
long i=0; i<n*n; i++ ) mat[i] = data[i];
103 long i, i1=m*rc1, i2=m*rc2;
104 for ( i=0; i<m; i++, i1++, i2++ ) swap(data[i1], data[i2]);
105 for ( i=0, i1=rc1, i2=rc2; i<n; i++, i1+=m, i2+=m ) swap(data[i1], data[i2]);
108 for ( l=clabel, i=0; l; l=l->
next ) {
109 if ( i==rc1 ) t1 = l;
110 if ( i==rc2 ) t2 = l;
112 t = *t1; *t1 = *t2; *t2 = t;
115 for ( l=rlabel, i=0; l; l=l->
next ) {
116 if ( i==rc1 ) t1 = l;
117 if ( i==rc2 ) t2 = l;
119 t = *t1; *t1 = *t2; *t2 = t;
double matrix_LU_decomposition(int n, double *a, double *b)
Matrix inversion and optionally solves a set of linear equations.
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Bmatrix operator*(Bmatrix &mat)
double & operator[](long i)
int matrix_rearrange(Bmatrix matrix, int *order)
Rearranges a matrix with a given order.
Bimage * img_from_matrix(Bmatrix matrix)
Converts a matrix to an image.
void column_add_label(Bstring &s)
General image parameter class.
void column_labels(Bstring *labels)
Bmatrix(long columns, long rows)
Bstring * column_labels()
void row_labels(Bstring *labels)
int matrix_show(Bmatrix matrix)
Displays the matrix contents.
Header file for matrix functions.
Header file for the string class.
Header file for 2D and 3D image I/O.
void row_add_label(Bstring &s)
Bmatrix matrix_random(long m, long n)
Generates a matrix with random values.
void swap_columns_rows(long rc1, long rc2)
Bmatrix(long columns, long rows, int cflag, int rflag)
int string_kill(Bstring *list)
Kills a string linked list.