[ADMB Users] fill matrix with a vector

dave fournier davef at otter-rsch.com
Thu Mar 24 12:49:46 PDT 2011


Here is an example with safety checks for the fill function



#include <admodel.h>

void fill(const dmatrix& _d,const dvector& _v)
{
   ADUNCONST(dmatrix,d)
   ADUNCONST(dvector,v)
   int mmin =d.indexmin();
   int mmax =d.indexmax();
   int sz=0;
   int i;
   ivector sz1(mmin,mmax);
   for (i=mmin;i<=mmax;i++)
   {
     sz1(i)=d(i).indexmax()-d(i).indexmin()+1;
     sz+=sz1(i);
   }
   if (sz != v.indexmax()-v.indexmin()+1)
   {
     cerr << "Error in sizes in function"
       " void fill(const dmatrix& _d,const dvector& v)" << endl;
     ad_exit(1);
   }
   int offset=v.indexmin();
   for (i=mmin;i<=mmax;i++)
   {
     d(i)=v(offset,offset+sz1(i)-1).shift(d(i).indexmin());
   }
}




More information about the Users mailing list