Sponsored Content
Top Forums Programming C++: Creating Matrix template using vector Post 302891019 by kristinu on Monday 3rd of March 2014 09:41:38 AM
Old 03-03-2014
C++: Creating Matrix template using vector

I want to create a Matrix template that uses vector. For the time being I want to create the following operations. I need setting the implementation for the operations.
Maybe I do not have to use a pointer either.



Code:
template <class T>
class Matrix {

protected:

  typedef vector<T>*  VP;

  int  M;    ///< Number of rows
  int  N;    ///< Number of column
  VP*  MAT;  ///< Matrix object (pointer to vector)

public:

  ////////////////////////////////////////////////
  /// \brief Creates a matrix
  /// Matrix b;

  Matrix
  (
   );

  ////////////////////////////////////////////////
  /// \brief Creates a matrix of size (m,n), 
  /// Matrix b(3,2);

  Matrix
  (
     const int  m,
     const int  n
   );

  ////////////////////////////////////////////////
  /// \brief Sets a matrix to another matrix
  /// Matrix b(a);

  Matrix
  (
     const Matrix&  a
   );

  ////////////////////////////////////////////////
  /// \brief Destroys a matrix

  ~Matrix 
  (
   );

};


template <class T>
inline 
Matrix<T>::Matrix
(
) {

  M = N = 0;

}


template <class T>
inline
Matrix<T>::Matrix
(
 const int  m,
 const int  n
 ) {

  M = m;
  N = n;
  MAT = new VP[M];

  for (int i = 0;  i < M;  i++)
    {
      MAT[i] = new vector<T> (N);
    }

}


template <class T>
inline
Matrix<T>::Matrix
(
 const Matrix<T>&  a
 ) {

  M = a.M;
  N = a.N;
  MAT = new VP[M];

  for (int i = 0;  i < M;  i++)
    {
      MAT[i] = new vector<T> (N);
    }

}


Last edited by kristinu; 03-03-2014 at 11:14 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Creating new system Makefile template

I am attempting to set-up a Makefile to use for a new system on a Sun Unix machine. I am new to creating Makefiles. I am trying to start simply by compiling a program. I am getting the following error message but an uncertain what 'Error Code 1' is. Is there a web site with Error Codes... (1 Reply)
Discussion started by: CaptainRo
1 Replies

2. Shell Programming and Scripting

Creating a matrix from files.

I need to create a large matrix so that I can feed that matrix to MATLAB for processing. The problem is creating that matrix because my data is completely scattered around files. 1. I have one big dictionary file which has words in newlines, like apple orange pineapple 2. I have some... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

3. 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

4. UNIX for Dummies Questions & Answers

BASH - Creating a Matrix

I'm trying to create a Matrix using bash. The expected output is .AB CDE FG 1 2 3 4 5 6 7 I'm a newbie in shell language, really appreciate if there is anyone who can guide me with this. Double post again, continued here (0 Replies)
Discussion started by: vinzping
0 Replies

5. Shell Programming and Scripting

Creating Matrix from file

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 (2 Replies)
Discussion started by: vinzping
2 Replies

6. Shell Programming and Scripting

Perl- creating a matrix from a 3 column file

Dear all, I'm new in perl scripting and I'm trying to creating a matrix from a 3 column file sorting data in a particular manner. In the final matrix I need to have the first column "IDs" on the header of the columns and the second column values on the header of each row. And the value fo the... (2 Replies)
Discussion started by: gabrysfe
2 Replies

7. Shell Programming and Scripting

Creating matrix from folders and subfolders

Hello, Greetings! please help me produce the following solution. I need to produce one big matrix file from several files in different levels. If it helps, the index folder provides information on chromosome index and the data folder provides information on values for chromosomes. there... (8 Replies)
Discussion started by: newbie83
8 Replies

8. Shell Programming and Scripting

Creating a matrix out of a longitudinal data set

Hi I do have a tab delimited file with 2 columns, which is stratified based on the first column. There are 1000's of values in the file. Below is an example of the input file 1 AB 1 AC 1 CC 1 DD 2 AB 2 CC 2 AC 2 AB 3 CF 3 CC 3 DD 4 AC 4 CC 4 AD (5 Replies)
Discussion started by: Kanja
5 Replies

9. Solaris

Creating a VMware template

Hello, I am creating a Solaris 11 template on my ESXI host. I would like each VM that is deployed from the template to have its own unique host fingerprint. With Linux, I simply delete host keys, which causes new keys to be generated at bootup (new VM deployment) Is there a way to do this... (1 Reply)
Discussion started by: firefoxx04
1 Replies

10. Shell Programming and Scripting

Creating verbal structures from a dictionary and a template

My main aim here is to create a database of verbs in a language to Hindi. The output if it works well will be put up on a University site for researchers to use for Machine Translation. This because one of the main weaknesses of MT is in the area of verbs. Sorry for the long post but the problem... (4 Replies)
Discussion started by: gimley
4 Replies
puzawa(4rheolef)						    rheolef-6.1 						  puzawa(4rheolef)

NAME
puzawa -- Uzawa algorithm. SYNOPSIS
template <class Matrix, class Vector, class Preconditioner, class Real> int puzawa (const Matrix &A, Vector &x, const Vector &b, const Preconditioner &M, int &max_iter, Real &tol, const Real& rho, odiststream *p_derr=0); EXAMPLE
The simplest call to 'puzawa' has the folling form: size_t max_iter = 100; double tol = 1e-7; int status = puzawa(A, x, b, EYE, max_iter, tol, 1.0, &derr); DESCRIPTION
puzawa solves the linear system A*x=b using the Uzawa method. The Uzawa method is a descent method in the direction opposite to the gradi- ent, with a constant step length 'rho'. The convergence is assured when the step length 'rho' is small enough. If matrix A is symmetric positive definite, please uses 'pcg' that computes automatically the optimal descdnt step length at each iteration. The return value indicates convergence within max_iter (input) iterations(0), or no convergence within max_iter iterations(1). Upon suc- cessful return, output arguments have the following values: x approximate solution to Ax = b max_iter the number of iterations performed before the tolerance was reached tol the residual after the final iteration IMPLEMENTATION
template < class Matrix, class Vector, class Preconditioner, class Real, class Size> int puzawa(const Matrix &A, Vector &x, const Vector &Mb, const Preconditioner &M, Size &max_iter, Real &tol, const Real& rho, odiststream *p_derr, std::string label) { Vector b = M.solve(Mb); Real norm2_b = dot(Mb,b); Real norm2_r = norm2_b; if (norm2_b == Real(0)) norm2_b = 1; if (p_derr) (*p_derr) << "[" << label << "] #iteration residue" << std::endl; for (Size n = 0; n <= max_iter; n++) { Vector Mr = A*x - Mb; Vector r = M.solve(Mr); norm2_r = dot(Mr, r); if (p_derr) (*p_derr) << "[" << label << "] " << n << " " << sqrt(norm2_r/norm2_b) << std::endl; if (norm2_r <= sqr(tol)*norm2_b) { tol = sqrt(norm2_r/norm2_b); max_iter = n; return 0; } x -= rho*r; } tol = sqrt(norm2_r/norm2_b); return 1; } rheolef-6.1 rheolef-6.1 puzawa(4rheolef)
All times are GMT -4. The time now is 04:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy