Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: matrices as vectors
Posted:
Feb 20, 2013 3:31 AM
|
|
On Tue, 19 Feb 2013, leonard14279@gmail.com wrote: > Had the idea to represent a 2d-matrix as a 1d-vector. > Have an existing program to perform matrix operations, where a matrix is > represented as an array of arrays. > Seems like the code would be more straightforward if a matrix were > represented as a 1d-vector. > Need a function to map [ row, col ] indices to an index [ n ], and > vice-versa. Does that mean anything? Are you wanting to map n by m matrices to 1 by n matrices? That can't be done without loosing lots of information.
> Then the rest should be straightforward. > So we have two functions ... > > ij-to-n( row, col ) { > n = row * numrows + col; > } > > n-to-ij( n ) { > row = ( n - col ) / numrows; > col = n - ( row * numrows ); > }
Those aren't well defined functions, they're snippits of some alian code.
> Then the rest of the code can be refactored to use the 1d-vector > representation of a 2d-matrix. I don't know what you're talking about. Do you? You can represent a n by m matrice by a colume of m n-dimensional vectors.
> The question is, are there already existing formulas for matrix > operations, where the matrix is represented as a 1d-vector? Depends upon what you mean.
|
|
|
|