[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: oct file: multiply a matrix by a vector
From: |
Robert A. Macy |
Subject: |
Re: oct file: multiply a matrix by a vector |
Date: |
Sat, 02 Jul 2005 10:38:43 -0700 |
Will that be faster than...
function matout=elementdivide(mat1,mat2);
% proper checks
[rowsmat1,columnsmat1]=size(mat1);
matout=mat1./(ones(rowsmat1,1)*mat2);
...?
- Robert -
On Sat, 02 Jul 2005 12:32:57 -0400
Brian Blais <address@hidden> wrote:
> 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
-------------------------------------------------------------