[ADMB Users] use of .sub

dave fournier davef at otter-rsch.com
Thu Feb 28 07:57:21 PST 2013


> I'm trying to nail down the proper syntax for employing .sub to identify
> portions of a matrix. Made some progress by trial and error, but still
> some obstacles. For instance below I try to fill a single given column
> with a vector, but get an error message that dvar_matrix::operator
> cannot be matched to dvar_vector. This a syntax and/or format problem?
>
> A matrix of age (row) by year (column), trying to fill the right margin.
>
> 	utfmat.sub(1,na).sub(ny,ny) = fly;
Easiest way for someone to understand this stuff (overloaded operators 
in C++)
is to compile in debug mode and walk through the code.  then you would 
see that

        utfmat.sub(1,na)

is a matrix so think of it as M. then the second sub is

     M.sub(ny,ny)

which is another matrix with 1 row (not 1 column).

The problme is that a matrix can either be stored by rows or by columns.
In ADMB it is stored by rows. so

      column(M,ny)

is a vector whose elements are equal of the ny column of M, but it
is *NOT* the ny column of M so if you write

            column(M,ny)=v;

M will not get changed.









More information about the Users mailing list