MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
matrix.h File Reference
#include <stdio.h>
Include dependency graph for matrix.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  matrix
 
struct  vector
 

Macros

#define W_M_NONE   (0x00U)
 
#define W_M_TEXT   (0x01U)
 
#define W_M_BIN   (0x02U)
 
#define W_M_BIN_ROW   (0x04U)
 

Typedefs

typedef struct matrix matrix
 
typedef struct vector vector
 

Enumerations

enum  mat_res_t {
  MAT_OK = 0, MAT_DIMENSION, MAT_NO_MEMORY, MAT_INPUT,
  MAT_GEN_ERROR
}
 

Functions

mat_res_t matrix_init (matrix *, unsigned, unsigned)
 
mat_res_t vector_init (vector *, unsigned)
 
mat_res_t matrix_destroy (matrix *)
 
mat_res_t vector_destroy (vector *)
 
mat_res_t matrix_null (matrix *)
 
mat_res_t matrix_eye (matrix *, double)
 
mat_res_t matrix_copy (matrix *, matrix *, double)
 
mat_res_t vector_copy (vector *, vector *, double)
 
mat_res_t vector_null (vector *)
 
mat_res_t matrix_prod (matrix *, matrix *, matrix *, double)
 
mat_res_t matrix_prod_sym (matrix *, matrix *, matrix *, double)
 
mat_res_t matrix_prod_transpose (matrix *, matrix *, matrix *, double)
 
mat_res_t matrix_transpose_prod (matrix *, matrix *, matrix *, double)
 
mat_res_t matrix_vector_prod (matrix *, vector *, vector *)
 
mat_res_t matrixT_vector_prod (matrix *, vector *, vector *)
 
mat_res_t matrix_sum (matrix *, matrix *, matrix *, double)
 
mat_res_t matrix_sum_transpose (matrix *, matrix *, matrix *, double)
 
mat_res_t vector_sum (vector *, vector *, vector *, double)
 
mat_res_t matrix_transpose (matrix *, matrix *)
 
mat_res_t scalar_prod (vector *, vector *, double *)
 
mat_res_t vector_vector_prod (vector *, vector *, matrix *, double)
 
mat_res_t matrix_write (matrix *, FILE *, unsigned)
 
mat_res_t vector_write (vector *, FILE *, unsigned)
 
mat_res_t matrix_read (matrix *, FILE *, unsigned)
 
mat_res_t vector_read (vector *, FILE *, unsigned)
 
mat_res_t matrix_random (matrix *, double, double)
 
mat_res_t vector_random (vector *, double, double)
 
mat_res_t sub_matrix_extract (matrix *, matrix *, unsigned, unsigned)
 
mat_res_t sub_matrix_insert (matrix *, matrix *, unsigned, unsigned)
 
double mean_value (matrix *, int)
 
double variance (matrix *, int)
 
double maximum (matrix *, int)
 
double minimum (matrix *, int)
 
double matrix_trace (matrix *)
 
void matrix_error (mat_res_t, const char *)
 

Macro Definition Documentation

#define W_M_BIN   (0x02U)

Definition at line 48 of file matrix.h.

Referenced by ANN_DataRead(), ANN_DataWrite(), ANN_init(), ANN_write(), main(), matrix_write(), and vector_write().

#define W_M_BIN_ROW   (0x04U)

Definition at line 49 of file matrix.h.

Referenced by vector_write().

#define W_M_NONE   (0x00U)

Definition at line 46 of file matrix.h.

#define W_M_TEXT   (0x01U)

Definition at line 47 of file matrix.h.

Referenced by ANN_write(), main(), matrix_write(), and vector_write().

Typedef Documentation

typedef struct matrix matrix
typedef struct vector vector

Enumeration Type Documentation

enum mat_res_t
Enumerator
MAT_OK 
MAT_DIMENSION 
MAT_NO_MEMORY 
MAT_INPUT 
MAT_GEN_ERROR 

Definition at line 52 of file matrix.h.

52  {
53  MAT_OK = 0,
56  MAT_INPUT,
58 } mat_res_t;
Definition: matrix.h:53
mat_res_t
Definition: matrix.h:52

Function Documentation

mat_res_t matrix_copy ( matrix ,
matrix ,
double   
)

Definition at line 140 of file matrix.c.

References matrix::mat, MAT_DIMENSION, MAT_OK, matrix_error(), matrix::Ncolumn, and matrix::Nrow.

Referenced by main().

140  {
141 
142  unsigned i, j;
143 
144  /* controllo dimensionale */
145  if( MAT1->Ncolumn != MAT2->Ncolumn || MAT1->Nrow != MAT2->Nrow){
146  matrix_error( MAT_DIMENSION, "matrix_copy" );
147  return MAT_DIMENSION;
148  }
149 
150  for( i=0; i<MAT1->Nrow; i++ ){
151  for( j=0; j<MAT1->Ncolumn; j++ ){
152  MAT1->mat[i][j] = K*MAT2->mat[i][j];
153  }
154  }
155 
156  return MAT_OK;
157 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53

Here is the call graph for this function:

mat_res_t matrix_destroy ( matrix )

Definition at line 84 of file matrix.c.

References matrix::mat, MAT_OK, and matrix::Nrow.

Referenced by ANN_destroy(), and main().

84  {
85 
86  unsigned i;
87 
88  for( i=0; i<MAT->Nrow; i++ ){
89  free(MAT->mat[i]);
90  }
91  free(MAT->mat);
92 
93  return MAT_OK;
94 }
Definition: matrix.h:53
void matrix_error ( mat_res_t  ,
const char *   
)

Definition at line 535 of file matrix.c.

References MAT_DIMENSION, MAT_GEN_ERROR, MAT_INPUT, and MAT_NO_MEMORY.

Referenced by matrix_copy(), matrix_eye(), matrix_init(), matrix_null(), matrix_prod(), matrix_prod_sym(), matrix_prod_transpose(), matrix_sum(), matrix_sum_transpose(), matrix_transpose(), matrix_transpose_prod(), matrix_vector_prod(), matrixT_vector_prod(), scalar_prod(), sub_matrix_extract(), sub_matrix_insert(), vector_copy(), vector_init(), vector_null(), vector_sum(), and vector_vector_prod().

535  {
536 
537  switch(error) {
538  case MAT_NO_MEMORY: fprintf( stderr, "Memory error( @ %s )\n", string );
539  break;
540  case MAT_DIMENSION: fprintf( stderr, "Matrix dimension mismatch( @ %s )\n", string );
541  break;
542  case MAT_INPUT: fprintf( stderr, "Reading error( @ %s )\n",string );
543  break;
544  case MAT_GEN_ERROR: fprintf( stderr, "Error( @ %s )\n",string );
545  break;
546  default: break;
547  }
548 }
int error(const char *test, int value)
mat_res_t matrix_eye ( matrix ,
double   
)

Definition at line 122 of file matrix.c.

References matrix::mat, MAT_GEN_ERROR, MAT_OK, matrix_error(), matrix_null(), and matrix::Nrow.

122  {
123 
124  unsigned i;
125 
126  /* azzero la matrice del risultato */
127  if( matrix_null(MAT) != MAT_OK ){
128  matrix_error( MAT_GEN_ERROR, "matrix_eye" );
129  return MAT_GEN_ERROR;
130  }
131 
132  for( i=0; i<MAT->Nrow; i++ ){
133  MAT->mat[i][i] = K;
134  }
135 
136  return MAT_OK;
137 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53
mat_res_t matrix_null(matrix *MAT)
Definition: matrix.c:107

Here is the call graph for this function:

mat_res_t matrix_init ( matrix ,
unsigned  ,
unsigned   
)

Definition at line 43 of file matrix.c.

References matrix::mat, MAT_DIMENSION, MAT_NO_MEMORY, MAT_OK, matrix_error(), matrix::Ncolumn, and matrix::Nrow.

Referenced by ANN_DataRead(), ANN_init(), ANN_vector_matrix_init(), and main().

43  {
44 
45  unsigned i;
46 
47  if( Nrow<= 0 || Ncolumn <= 0 ){
48  matrix_error( MAT_DIMENSION, "matrix_init" );
49  return MAT_DIMENSION;
50  }
51 
52  MAT->Nrow = Nrow;
53  MAT->Ncolumn = Ncolumn;
54  if( !( MAT->mat = (double **)calloc( Nrow, sizeof(double *) ) ) ){
55  matrix_error( MAT_NO_MEMORY, "matrix_init" );
56  return MAT_NO_MEMORY;
57  }
58  for( i=0; i<Nrow; i++ ){
59  if( !( MAT->mat[i] = (double *)calloc( Ncolumn, sizeof(double) ) ) ){
60  matrix_error( MAT_NO_MEMORY, "matrix_init" );
61  return MAT_NO_MEMORY;
62  }
63  }
64 
65  return MAT_OK;
66 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53

Here is the call graph for this function:

mat_res_t matrix_null ( matrix )

Definition at line 107 of file matrix.c.

References matrix::mat, MAT_GEN_ERROR, MAT_OK, matrix_error(), matrix::Ncolumn, and matrix::Nrow.

Referenced by ANN_reset(), matrix_eye(), matrix_prod(), matrix_prod_sym(), matrix_prod_transpose(), and matrix_transpose_prod().

107  {
108 
109  unsigned i;
110 
111  for( i=0; i<MAT->Nrow; i++ ){
112  if( !(memset( MAT->mat[i], 0, MAT->Ncolumn*sizeof(double) ) ) ){
113  matrix_error( MAT_GEN_ERROR, "matrix_null" );
114  return MAT_GEN_ERROR;
115  }
116  }
117 
118  return MAT_OK;
119 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53

Here is the call graph for this function:

mat_res_t matrix_prod ( matrix ,
matrix ,
matrix ,
double   
)

Definition at line 187 of file matrix.c.

References matrix::mat, MAT_DIMENSION, MAT_GEN_ERROR, MAT_OK, matrix_error(), matrix_null(), matrix::Ncolumn, and matrix::Nrow.

187  {
188 
189  unsigned i,j,k;
190 
191  /* controllo dimensionale */
192  if( MAT1->Ncolumn != MAT2->Nrow || MAT_R->Nrow != MAT1->Nrow || MAT_R->Ncolumn != MAT2->Ncolumn ){
193  matrix_error( MAT_DIMENSION, "matrix_prod" );
194  return MAT_DIMENSION;
195  }
196  /* azzero la matrice del risultato */
197  if( matrix_null(MAT_R) != MAT_OK ){
198  matrix_error( MAT_GEN_ERROR, "matrix_prod" );
199  return MAT_GEN_ERROR;
200  }
201  for( i=0; i<MAT1->Nrow; i++ ){
202  for( j=0; j<MAT2->Ncolumn; j++ ){
203  for( k=0; k<MAT1->Ncolumn; k++ ){
204  MAT_R->mat[i][j] += K*MAT1->mat[i][k]*MAT2->mat[k][j];
205  }
206  }
207  }
208 
209  return MAT_OK;
210 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53
mat_res_t matrix_null(matrix *MAT)
Definition: matrix.c:107

Here is the call graph for this function:

mat_res_t matrix_prod_sym ( matrix ,
matrix ,
matrix ,
double   
)

Definition at line 212 of file matrix.c.

References matrix::mat, MAT_DIMENSION, MAT_GEN_ERROR, MAT_OK, matrix_error(), matrix_null(), matrix::Ncolumn, and matrix::Nrow.

212  {
213 
214  unsigned i,j,k;
215 
216  /* controllo dimensionale */
217  if( MAT1->Ncolumn != MAT2->Nrow || MAT_R->Nrow != MAT1->Nrow || MAT_R->Ncolumn != MAT2->Ncolumn ){
218  matrix_error( MAT_DIMENSION, "matrix_prod" );
219  return MAT_DIMENSION;
220  }
221  /* azzero la matrice del risultato */
222  if( matrix_null(MAT_R) != MAT_OK ){
223  matrix_error( MAT_GEN_ERROR, "matrix_prod" );
224  return MAT_GEN_ERROR;
225  }
226  for( i=0; i<MAT1->Nrow; i++ ){
227  for( j=i; j<MAT2->Ncolumn; j++ ){
228  for( k=0; k<MAT1->Ncolumn; k++ ){
229  MAT_R->mat[i][j] += K*MAT1->mat[i][k]*MAT2->mat[k][j];
230  }
231  MAT_R->mat[j][i] = MAT_R->mat[i][j];
232  }
233  }
234 
235  return MAT_OK;
236 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53
mat_res_t matrix_null(matrix *MAT)
Definition: matrix.c:107

Here is the call graph for this function:

mat_res_t matrix_prod_transpose ( matrix ,
matrix ,
matrix ,
double   
)

Definition at line 284 of file matrix.c.

References matrix::mat, MAT_DIMENSION, MAT_GEN_ERROR, MAT_OK, matrix_error(), matrix_null(), matrix::Ncolumn, and matrix::Nrow.

284  {
285 
286  unsigned i,j,k;
287 
288  /* controllo dimensionale */
289  if( MAT1->Ncolumn != MAT2->Ncolumn || MAT_R->Nrow != MAT1->Nrow || MAT_R->Ncolumn != MAT2->Nrow ){
290  matrix_error( MAT_DIMENSION, "matrix_prod_transpose" );
291  return MAT_DIMENSION;
292  }
293  /* azzero la matrice del risultato */
294  if( matrix_null(MAT_R) != MAT_OK ){
295  matrix_error( MAT_GEN_ERROR, "matrix_prod_transpose" );
296  return MAT_GEN_ERROR;
297  }
298  for( i=0; i<MAT1->Nrow; i++ ){
299  for( j=0; j<MAT2->Nrow; j++ ){
300  for( k=0; k<MAT1->Ncolumn; k++ ){
301  MAT_R->mat[i][j] += K*MAT1->mat[i][k]*MAT2->mat[j][k];
302  }
303  }
304  }
305 
306  return MAT_OK;
307 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53
mat_res_t matrix_null(matrix *MAT)
Definition: matrix.c:107

Here is the call graph for this function:

mat_res_t matrix_random ( matrix ,
double  ,
double   
)

Definition at line 552 of file matrix.c.

References matrix::mat, MAT_OK, matrix::Ncolumn, and matrix::Nrow.

Referenced by main().

552  {
553 
554  double y;
555  unsigned i,j;
556 
557  for( i=0; i<MAT->Nrow; i++ ){
558  for( j=0; j<MAT->Ncolumn; j++ ){
559  y = rand();
560  y = y/RAND_MAX;
561  y = y*(max-min);
562  y += min ;
563  MAT->mat[i][j] = y;
564  }
565  }
566 
567  return MAT_OK;
568 }
Definition: matrix.h:53
mat_res_t matrix_read ( matrix ,
FILE *  ,
unsigned   
)

Definition at line 506 of file matrix.c.

References matrix::mat, MAT_INPUT, MAT_OK, matrix::Ncolumn, and matrix::Nrow.

Referenced by ANN_DataRead(), and ANN_init().

506  {
507 
508  unsigned i,j;
509 
510  for( i=0; i<MAT->Nrow; i++ ){
511  for( j=0; j<MAT->Ncolumn; j++ ){
512  if( fscanf( fh, "%le", &MAT->mat[i][j] ) <= 0 ){
513  return MAT_INPUT;
514  }
515  }
516  }
517 
518  return MAT_OK;
519 }
Definition: matrix.h:53
mat_res_t matrix_sum ( matrix ,
matrix ,
matrix ,
double   
)

Definition at line 409 of file matrix.c.

References matrix::mat, MAT_DIMENSION, MAT_OK, matrix_error(), matrix::Ncolumn, and matrix::Nrow.

Referenced by ANN_TrainingEpoch(), and ANN_WeightUpdate().

409  {
410 
411  unsigned i,j;
412 
413  /* controllo dimensionale */
414  if( MAT1->Ncolumn != MAT2->Ncolumn || MAT_R->Ncolumn != MAT1->Ncolumn || MAT_R->Nrow != MAT2->Nrow || MAT1->Nrow != MAT2->Nrow ){
415  matrix_error( MAT_DIMENSION, "matrix_sum" );
416  return MAT_DIMENSION;
417  }
418  for( i=0; i<MAT1->Nrow; i++ ){
419  for( j=0; j<MAT1->Ncolumn; j++ ){
420  MAT_R->mat[i][j] = MAT1->mat[i][j] + K*MAT2->mat[i][j];
421  }
422  }
423 
424  return MAT_OK;
425 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53

Here is the call graph for this function:

mat_res_t matrix_sum_transpose ( matrix ,
matrix ,
matrix ,
double   
)

Definition at line 428 of file matrix.c.

References matrix::mat, MAT_DIMENSION, MAT_OK, matrix_error(), matrix::Ncolumn, and matrix::Nrow.

428  {
429 
430  unsigned i,j;
431 
432  /* controllo dimensionale */
433  if( MAT1->Ncolumn != MAT2->Nrow || MAT_R->Ncolumn != MAT1->Ncolumn || MAT_R->Nrow != MAT1->Nrow || MAT1->Nrow != MAT2->Ncolumn ){
434  matrix_error( MAT_DIMENSION, "matrix_sum_transpose" );
435  return MAT_DIMENSION;
436  }
437  for( i=0; i<MAT1->Nrow; i++ ){
438  for( j=0; j<MAT1->Ncolumn; j++ ){
439  MAT_R->mat[i][j] = MAT1->mat[i][j] + K*MAT2->mat[j][i];
440  }
441  }
442 
443  return MAT_OK;
444 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53

Here is the call graph for this function:

double matrix_trace ( matrix )

Definition at line 644 of file matrix.c.

References matrix::mat, and matrix::Nrow.

644  {
645 
646  unsigned i;
647  double trace;
648 
649  trace = 0.;
650  for( i=0; i<MAT->Nrow; i++ ){
651  trace += MAT->mat[i][i];
652  }
653 
654  return trace;
655 }
mat_res_t matrix_transpose ( matrix ,
matrix  
)

Definition at line 239 of file matrix.c.

References matrix::mat, MAT_DIMENSION, MAT_OK, matrix_error(), matrix::Ncolumn, and matrix::Nrow.

239  {
240 
241  unsigned i,j;
242 
243  /* controllo dimensionale */
244  if( MAT1->Ncolumn != MAT2->Nrow || MAT1->Nrow != MAT2->Ncolumn ){
245  matrix_error( MAT_DIMENSION, "matrix_transpose" );
246  return MAT_DIMENSION;
247  }
248 
249  for( i=0; i<MAT2->Nrow; i++ ){
250  for( j=0; j<MAT2->Ncolumn; j++ ){
251  MAT1->mat[j][i] = MAT2->mat[i][j];
252  }
253  }
254 
255  return MAT_OK;
256 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53

Here is the call graph for this function:

mat_res_t matrix_transpose_prod ( matrix ,
matrix ,
matrix ,
double   
)

Definition at line 258 of file matrix.c.

References matrix::mat, MAT_DIMENSION, MAT_GEN_ERROR, MAT_OK, matrix_error(), matrix_null(), matrix::Ncolumn, and matrix::Nrow.

258  {
259 
260  unsigned i,j,k;
261 
262  /* controllo dimensionale */
263  if( MAT1->Nrow != MAT2->Nrow || MAT_R->Nrow != MAT1->Ncolumn || MAT_R->Ncolumn != MAT2->Ncolumn ){
264  matrix_error( MAT_DIMENSION, "matrix_transpose_prod" );
265  return MAT_DIMENSION;
266  }
267  /* azzero la matrice del risultato */
268  if( matrix_null(MAT_R) != MAT_OK ){
269  matrix_error( MAT_GEN_ERROR, "matrix_transpose_prod" );
270  return MAT_GEN_ERROR;
271  }
272  for( i=0; i<MAT1->Ncolumn; i++ ){
273  for( j=0; j<MAT2->Ncolumn; j++ ){
274  for( k=0; k<MAT1->Nrow; k++ ){
275  MAT_R->mat[i][j] += K*MAT1->mat[k][i]*MAT2->mat[k][j];
276  }
277  }
278  }
279 
280  return MAT_OK;
281 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53
mat_res_t matrix_null(matrix *MAT)
Definition: matrix.c:107

Here is the call graph for this function:

mat_res_t matrix_vector_prod ( matrix ,
vector ,
vector  
)

Definition at line 354 of file matrix.c.

References vector::dimension, matrix::mat, MAT_DIMENSION, MAT_GEN_ERROR, MAT_OK, matrix_error(), matrix::Ncolumn, matrix::Nrow, vector::vec, and vector_null().

Referenced by ANN_dEdW().

354  {
355 
356  unsigned i,j;
357 
358  /* controllodimensionale */
359  if( MAT->Ncolumn != VEC->dimension || MAT->Nrow != VEC_R->dimension ){
360  matrix_error( MAT_DIMENSION, "matrix_vector_prod" );
361  return MAT_DIMENSION;
362  }
363  /* azzero il vettore risultato */
364  if( vector_null(VEC_R) != MAT_OK ){
365  matrix_error( MAT_GEN_ERROR, "matrix_vector_prod");
366  return MAT_GEN_ERROR;
367  }
368 
369  for( i=0; i<MAT->Nrow; i++ ){
370  for( j=0; j<MAT->Ncolumn; j++ ){
371  VEC_R->vec[i] += MAT->mat[i][j]*VEC->vec[j];
372  }
373  }
374 
375  return MAT_OK;
376 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
mat_res_t vector_null(vector *VEC)
Definition: matrix.c:176
Definition: matrix.h:53

Here is the call graph for this function:

mat_res_t matrix_write ( matrix ,
FILE *  ,
unsigned   
)

Definition at line 467 of file matrix.c.

References matrix::mat, MAT_OK, matrix::Ncolumn, matrix::Nrow, W_M_BIN, and W_M_TEXT.

Referenced by ANN_DataWrite(), ANN_write(), and main().

467  {
468 
469  unsigned i,j;
470 
471  if( flags & W_M_TEXT ) fprintf( fh, "matrix = [\n" );
472  if( flags & W_M_BIN ) fprintf( fh, "\n" );
473  for( i=0; i<MAT->Nrow; i++ ){
474  for( j=0; j<MAT->Ncolumn; j++ ){
475  fprintf( fh, "%15.16e ", MAT->mat[i][j] );
476  }
477  fprintf( fh, "\n");
478  }
479 
480  if( flags & W_M_TEXT ) fprintf( fh, "]\n" );
481  if( flags & W_M_BIN ) fprintf( fh, "\n" );
482 
483  return MAT_OK;
484 }
#define W_M_TEXT
Definition: matrix.h:47
Definition: matrix.h:53
#define W_M_BIN
Definition: matrix.h:48
mat_res_t matrixT_vector_prod ( matrix ,
vector ,
vector  
)

Definition at line 379 of file matrix.c.

References vector::dimension, matrix::mat, MAT_DIMENSION, MAT_GEN_ERROR, MAT_OK, matrix_error(), matrix::Ncolumn, matrix::Nrow, vector::vec, and vector_null().

Referenced by ANN_dEdW(), ANN_dXdW(), ANN_jacobian_matrix(), and ANN_sim().

379  {
380 
381  unsigned i,j;
382 
383  /* controllo dimensionale */
384  if( MAT->Nrow != VEC->dimension || MAT->Ncolumn != VEC_R->dimension ){
385  matrix_error( MAT_DIMENSION, "matrixT_vector_prod" );
386  return MAT_DIMENSION;
387  }
388  /* annullo il vettore risulatante */
389  if( vector_null(VEC_R) != MAT_OK ){
390  matrix_error( MAT_GEN_ERROR, "matrixT_vector_prod" );
391  return MAT_GEN_ERROR;
392  }
393 
394  //for( i=0; i<MAT->Nrow; i++ ){
395  // for( j=0; j<MAT->Ncolumn; j++ ){
396  // VEC_R->vec[j] += MAT->mat[i][j]*VEC->vec[i];
397  // }
398  //}
399  for( i=0; i<MAT->Ncolumn; i++ ){
400  for( j=0; j<MAT->Nrow; j++ ){
401  VEC_R->vec[i] += MAT->mat[j][i]*VEC->vec[j];
402  }
403  }
404 
405  return MAT_OK;
406 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
mat_res_t vector_null(vector *VEC)
Definition: matrix.c:176
Definition: matrix.h:53

Here is the call graph for this function:

double maximum ( matrix ,
int   
)

Definition at line 612 of file matrix.c.

References matrix::mat, MAX, and matrix::Nrow.

Referenced by main().

612  {
613 
614  unsigned i;
615  double MAX;
616 
617  MAX = MAT->mat[0][column];
618  for( i=0; i<MAT->Nrow; i++ ){
619  if( MAT->mat[i][column] > MAX ){
620  MAX = MAT->mat[i][column];
621  }
622  }
623 
624  return MAX;
625 }
float MAX
Definition: ann_in.c:96
double mean_value ( matrix ,
int   
)

Definition at line 586 of file matrix.c.

References matrix::mat, and matrix::Nrow.

Referenced by main(), and variance().

586  {
587 
588  unsigned i;
589  double mean = 0.;
590 
591  for( i=0; i<MAT->Nrow; i++ ){
592  mean += MAT->mat[i][column];
593  }
594  return( mean/MAT->Nrow );
595 }
double minimum ( matrix ,
int   
)

Definition at line 628 of file matrix.c.

References matrix::mat, MIN, and matrix::Nrow.

Referenced by main().

628  {
629 
630  unsigned i;
631  double MIN;
632 
633  MIN = MAT->mat[0][column];
634  for( i=0; i<MAT->Nrow; i++ ){
635  if( MAT->mat[i][column] < MIN ){
636  MIN = MAT->mat[i][column];
637  }
638  }
639 
640  return MIN;
641 }
float MIN
Definition: ann_in.c:95
mat_res_t scalar_prod ( vector ,
vector ,
double *   
)

Definition at line 310 of file matrix.c.

References vector::dimension, MAT_DIMENSION, MAT_OK, matrix_error(), and vector::vec.

310  {
311 
312  unsigned i;
313  double res;
314 
315  /* controllodimensionale */
316  if( VEC1->dimension != VEC2->dimension ){
317  matrix_error( MAT_DIMENSION, "matrix_vector_prod" );
318  return MAT_DIMENSION;
319  }
320 
321  res = 0.;
322  for( i=0; i<VEC1->dimension; i++){
323  res += VEC1->vec[i]*VEC2->vec[i];
324  }
325 
326  *RES = res;
327 
328  return MAT_OK;
329 
330 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53

Here is the call graph for this function:

mat_res_t sub_matrix_extract ( matrix ,
matrix ,
unsigned  ,
unsigned   
)

Definition at line 656 of file matrix.c.

References matrix::mat, MAT_DIMENSION, MAT_OK, matrix_error(), matrix::Ncolumn, and matrix::Nrow.

656  {
657 
658  unsigned i, j;
659 
660  if( (RowIndex+SUB->Nrow > BIG->Nrow) || (ColumnIndex+SUB->Ncolumn > BIG->Ncolumn) ){
661  matrix_error( MAT_DIMENSION, "sub_matrix_extract" );
662  return MAT_DIMENSION;
663  }
664 
665  for( i=0; i<SUB->Nrow; i++){
666  for( j=0; j<SUB->Ncolumn; j++){
667  SUB->mat[i][j] = BIG->mat[RowIndex+i][ColumnIndex+j];
668  }
669  }
670 
671  return MAT_OK;
672 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53

Here is the call graph for this function:

mat_res_t sub_matrix_insert ( matrix ,
matrix ,
unsigned  ,
unsigned   
)

Definition at line 674 of file matrix.c.

References matrix::mat, MAT_DIMENSION, MAT_OK, matrix_error(), matrix::Ncolumn, and matrix::Nrow.

674  {
675 
676  unsigned i, j;
677 
678  if( (RowIndex+SUB->Nrow > BIG->Nrow) || (ColumnIndex+SUB->Ncolumn > BIG->Ncolumn) ){
679  matrix_error( MAT_DIMENSION, "sub_matrix_insert" );
680  return MAT_DIMENSION;
681  }
682 
683  for( i=0; i<SUB->Nrow; i++){
684  for( j=0; j<SUB->Ncolumn; j++){
685  BIG->mat[RowIndex+i][ColumnIndex+j] = SUB->mat[i][j];
686  }
687  }
688 
689  return MAT_OK;
690 
691 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53

Here is the call graph for this function:

double variance ( matrix ,
int   
)

Definition at line 598 of file matrix.c.

References matrix::mat, mean_value(), and matrix::Nrow.

Referenced by main().

598  {
599 
600  unsigned i;
601  double mean, var = 0.;
602 
603  mean = mean_value( MAT, column);
604  for( i=0; i<MAT->Nrow; i++ ){
605  var += (MAT->mat[i][column]-mean)*(MAT->mat[i][column]-mean);
606  }
607 
608  return( var/MAT->Nrow );
609 }
double mean_value(matrix *MAT, int column)
Definition: matrix.c:586

Here is the call graph for this function:

mat_res_t vector_copy ( vector ,
vector ,
double   
)

Definition at line 159 of file matrix.c.

References vector::dimension, MAT_DIMENSION, MAT_OK, matrix_error(), and vector::vec.

159  {
160 
161  unsigned i;
162 
163  /* controllo dimensionale */
164  if( VEC1->dimension != VEC2->dimension){
165  matrix_error( MAT_DIMENSION, "vector_copy" );
166  return MAT_DIMENSION;
167  }
168 
169  for( i=0; i<VEC1->dimension; i++ ){
170  VEC1->vec[i] = K*VEC2->vec[i];
171  }
172 
173  return MAT_OK;
174 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53

Here is the call graph for this function:

mat_res_t vector_destroy ( vector )

Definition at line 97 of file matrix.c.

References MAT_OK, and vector::vec.

Referenced by ANN_destroy(), and main().

97  {
98 
99  free(VEC->vec);
100 
101  return MAT_OK;
102 }
Definition: matrix.h:53
mat_res_t vector_init ( vector ,
unsigned   
)

Definition at line 68 of file matrix.c.

References vector::dimension, MAT_DIMENSION, MAT_NO_MEMORY, MAT_OK, matrix_error(), and vector::vec.

Referenced by ANN_init(), ANN_vector_vector_init(), and main().

68  {
69  if( dimension<= 0 ){
70  matrix_error( MAT_DIMENSION, "vector_init" );
71  return MAT_DIMENSION;
72  }
73 
74  VEC->dimension = dimension;
75 
76  if( !( VEC->vec = (double *)calloc( dimension, sizeof(double) ) ) ){
77  matrix_error( MAT_NO_MEMORY, "vector_init");
78  return MAT_NO_MEMORY;
79  }
80 
81  return MAT_OK;
82 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53

Here is the call graph for this function:

mat_res_t vector_null ( vector )

Definition at line 176 of file matrix.c.

References vector::dimension, MAT_GEN_ERROR, MAT_OK, matrix_error(), and vector::vec.

Referenced by ANN_jacobian_matrix(), ANN_reset(), matrix_vector_prod(), and matrixT_vector_prod().

176  {
177 
178  if( !(memset( VEC->vec, 0, VEC->dimension*sizeof(double) ) ) ){
179  matrix_error( MAT_GEN_ERROR, "vector_null" );
180  return MAT_GEN_ERROR;
181  }
182 
183  return MAT_OK;
184 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53

Here is the call graph for this function:

mat_res_t vector_random ( vector ,
double  ,
double   
)

Definition at line 570 of file matrix.c.

References vector::dimension, MAT_OK, and vector::vec.

570  {
571 
572  double y;
573  unsigned i;
574 
575  for( i=0; i<VEC->dimension; i++ ){
576  y = rand();
577  y = y/RAND_MAX;
578  y = y*(max-min);
579  y += min ;
580  VEC->vec[i] = y;
581  }
582  return MAT_OK;
583 }
Definition: matrix.h:53
mat_res_t vector_read ( vector ,
FILE *  ,
unsigned   
)

Definition at line 522 of file matrix.c.

References vector::dimension, MAT_INPUT, MAT_OK, and vector::vec.

522  {
523 
524  unsigned i;
525 
526  for( i=0; i<VEC->dimension; i++ ){
527  if( fscanf( fh, "%le", &VEC->vec[i] ) <= 0 ){
528  return MAT_INPUT;
529  }
530  }
531 
532  return MAT_OK;
533 }
Definition: matrix.h:53
mat_res_t vector_sum ( vector ,
vector ,
vector ,
double   
)

Definition at line 447 of file matrix.c.

References vector::dimension, MAT_DIMENSION, MAT_OK, matrix_error(), and vector::vec.

447  {
448 
449  unsigned i;
450 
451  /* controllo dimensionale */
452  if( VEC1->dimension != VEC2->dimension || VEC_R->dimension != VEC1->dimension ){
453  matrix_error( MAT_DIMENSION, "vector_sum" );
454  return MAT_DIMENSION;
455  }
456  for( i=0; i<VEC1->dimension; i++ ){
457  VEC_R->vec[i] = VEC1->vec[i] + K*VEC2->vec[i];
458  }
459 
460  return MAT_OK;
461 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53

Here is the call graph for this function:

mat_res_t vector_vector_prod ( vector ,
vector ,
matrix ,
double   
)

Definition at line 333 of file matrix.c.

References vector::dimension, matrix::mat, MAT_DIMENSION, MAT_OK, matrix_error(), matrix::Ncolumn, matrix::Nrow, and vector::vec.

333  {
334 
335  unsigned i, j;
336 
337  /* controllodimensionale */
338  if( VEC1->dimension != RES->Nrow || VEC2->dimension != RES->Ncolumn){
339  matrix_error( MAT_DIMENSION, "vector_vector_prod" );
340  return MAT_DIMENSION;
341  }
342 
343  for( i=0; i<VEC1->dimension; i++){
344  for( j=0; j<VEC2->dimension; j++){
345  RES->mat[i][j] = K*VEC1->vec[i]*VEC2->vec[j];
346  }
347  }
348 
349  return MAT_OK;
350 
351 }
void matrix_error(mat_res_t error, const char *string)
Definition: matrix.c:535
Definition: matrix.h:53

Here is the call graph for this function:

mat_res_t vector_write ( vector ,
FILE *  ,
unsigned   
)

Definition at line 487 of file matrix.c.

References vector::dimension, MAT_OK, vector::vec, W_M_BIN, W_M_BIN_ROW, and W_M_TEXT.

Referenced by main().

487  {
488 
489  unsigned i;
490 
491  if( flags & W_M_TEXT ) fprintf( fh, "vector = [\n" );
492  /*if( flags & W_M_BIN ) fprintf( fh, "\n" );*/
493  for( i=0; i<VEC->dimension; i++ ){
494  if( flags & W_M_BIN ) fprintf( fh, "\n" );
495  fprintf( fh, "%15.16e ", VEC->vec[i] );
496  }
497 
498  if( flags & W_M_TEXT ) fprintf( fh, "]\n" );
499  if( flags & W_M_BIN ) fprintf( fh, "\n" );
500  if( flags & W_M_BIN_ROW ) fprintf( fh, "\n" );
501 
502  return MAT_OK;
503 }
#define W_M_TEXT
Definition: matrix.h:47
Definition: matrix.h:53
#define W_M_BIN
Definition: matrix.h:48
#define W_M_BIN_ROW
Definition: matrix.h:49