Page 1 of 1

Matrix<Rational> in C++

Posted: 20 Jun 2013, 18:20
by ebbe1990
Hello

can anybody tell my why for a Matrix<Rational> matrix(n,m); the following expression is wrong?

matrix.row(0).col(0)

or is there an easier way to accesses the elements of a matrix?

thank you :)

Re: Matrix<Rational> in C++

Posted: 20 Jun 2013, 20:07
by gawrilow
row(i) gives you a selected row represented by an object with Vector-like interface, that is, access to a single element there is provided via operator[]. The same for columns: col(j) returns something behaving like a Vector. The following four expressions are functionally equivalent:

m[j] m.row(i)[j] m.col(j) m(i,j)

The last one is the most efficient, because it does not create any temporary intermediate objects.

Re: Matrix<Rational> in C++

Posted: 20 Jun 2013, 20:22
by ebbe1990
That helps alot. Thank you