help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

oct file: multiply a matrix by a vector


From: Brian Blais
Subject: oct file: multiply a matrix by a vector
Date: Sat, 02 Jul 2005 12:32:57 -0400
User-agent: Mozilla Thunderbird 0.8 (X11/20040913)

Hello,

I was wondering if there is a more efficient way of doing the following
in an oct file.  Many times I want to have a matrix multiplied by a
vector, in a way that each row of the matrix is element-by-element
multiplied by the vector.  I wrote the following, straightforward, code
for it but was wondering if there is a more advised way of doing it.  My
primary interest is in speed, but there may be other reasons to not do
it the way I have written.

                thanks,

                        Brian Blais

int rquotient(Matrix &mat1,Matrix &mat2) {

  Matrix retval;

  if (mat1.cols()!=mat2.cols()) {
    error("Size mismatch");
    return(1);
  }

  for (int i=0; i<mat1.rows(); i++) {
    for (int j=0; j<mat1.cols(); j++) {
      mat1(i,j)/=mat2(j);
    }

  }


  return(0);

}

--
-----------------

            address@hidden
            http://web.bryant.edu/~bblais



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]