Matrix code in C++


 
Thread Tools Search this Thread
Top Forums Programming Matrix code in C++
# 1  
Old 06-26-2011
Matrix code in C++

I have the code below in C++ and am trying to understand what these do and how to call them.

Code:
template <class Type>
class Matrix {

public:

  Matrix();

  Matrix(
    const int  m,
    const int  n );

  Matrix(
    const Matrix&  A );

  ~Matrix();

  Vector<Type>&
  operator [] (
    const int  i );

  Vector<Type>&
  operator [] (
    const int  i ) const;

  Vector<Type>&
  operator () (
    const int  i );

  Vector<Type>&
  operator () (
    const int  i ) const;

protected:

  typedef Vector<Type>*  VP;
  int  M;
  int  N;
  VP*  Mat;

};

template <class Type>
inline
Vector<Type>&
Matrix<Type>::operator [] (
  const int  i ) {

  assert((i < M) && (i >= 0));
  return (*Mat[i]);

}

template <class Type>
inline
Vector<Type>&
Matrix<Type>::operator [] (
  const int  i ) const {

  assert((i < M) && (i >= 0));
  return (*Mat[i]);

}

template <class Type>
inline
Vector<Type>&
Matrix<Type>::operator () (
  const int  i ) {

  if (i >= M) {
      do {
          i -= M;
      } while (i >= M);

  } else if (i < 0) {
      do {
          i += M;
      } while (i < 0);
  }
  return (*Mat[i]);

}

template <class Type>
inline
Vector<Type>&
Matrix<Type>::operator () (
  const int  i ) const {

    if (i >= M) {
        do {
            i -= M;
        } while (i >= M);

    } else if (i < 0) {
        do {
            i += M;
        } while (i < 0);
    }
    return (*Mat[i]);
}

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Matrix multiplication

I have two files. Row id in File1 matches the column id in file2 (starting from column7 )except the last 2 characters. File1 has 50 rows and File 2 has 56 columns. If the id matches I want to multiply the value in column3 of File1 to the entire column in File2. and in the final output print only... (11 Replies)
Discussion started by: Akang
11 Replies

2. Shell Programming and Scripting

Randomize a matrix

--please have a look at my third post in this thread! there I explained it more clearly-- Hey guys. I posted a complex problem few days back. No reply! :| Here is simplified question: I have a matrix with 0/1: * col1 col2 col3 row1 1 0 1 row2 0 0 ... (5 Replies)
Discussion started by: @man
5 Replies

3. Programming

Matrix parsing help !

Hello every body ! I'm a new in this forum and beginner in Perl scripting and I have some problems :(:(:(! I have a big file like that : ID1 ID2 Identity chromosome07_194379 chromosome01_168057 0.975 chromosome01_100293 chromosome01_168057 ... (23 Replies)
Discussion started by: mchimich
23 Replies

4. Ubuntu

Creating Matrix

Hi all, I'm a newbie in shell scripting and currently I'm trying to create a matrix using bash. The Output will look like this AB CDE FG 1 2 3 4 5 6 7 I'm stuck on the ABCDEFG display. printFlightSeats() { rows=7 columns=7 for ((i=0;i<=$rows;i++)) do (0 Replies)
Discussion started by: vinzping
0 Replies

5. Shell Programming and Scripting

awk? adjacency matrix to adjacency list / correlation matrix to list

Hi everyone I am very new at awk but think that that might be the best strategy for this. I have a matrix very similar to a correlation matrix and in practical terms I need to convert it into a list containing the values from the matrix (one value per line) with the first field of the line (row... (5 Replies)
Discussion started by: stonemonkey
5 Replies

6. Ubuntu

How to convert full data matrix to linearised left data matrix?

Hi all, Is there a way to convert full data matrix to linearised left data matrix? e.g full data matrix Bh1 Bh2 Bh3 Bh4 Bh5 Bh6 Bh7 Bh1 0 0.241058 0.236129 0.244397 0.237479 0.240767 0.245245 Bh2 0.241058 0 0.240594 0.241931 0.241975 ... (8 Replies)
Discussion started by: evoll
8 Replies

7. Shell Programming and Scripting

Matrix

Hi All I would like to merge multiple files with the same row and column size into a matrix format In a folder I have multiple files in the following format vi 12.txt a 1 b 5 c 7 d 0 vi 45.txt a 3 b 6 c 9 d 2 vi 9.txt a 4 (7 Replies)
Discussion started by: Lucky Ali
7 Replies

8. Shell Programming and Scripting

diagonal matrix to square matrix

Hello, all! I am struggling with a short script to read a diagonal matrix for later retrieval. 1.000 0.234 0.435 0.123 0.012 0.102 0.325 0.412 0.087 0.098 1.000 0.111 0.412 0.115 0.058 0.091 0.190 0.045 0.058 1.000 0.205 0.542 0.335 0.054 0.117 0.203 0.125 1.000 0.587 0.159 0.357... (11 Replies)
Discussion started by: yifangt
11 Replies

9. Shell Programming and Scripting

matrix indexes

I wanted to use matrixs in awk and got some problem, here is some of the script code, from the BEGIN tag: row_char="a";row_char="b";row_char="c";row_char="d";row_char="e"$ row_char="h";row_char="i";row_char="j";row_char="k"; from the proccess passage: sentence,1]=1; diffrence=4; i=7;... (2 Replies)
Discussion started by: tal
2 Replies
Login or Register to Ask a Question