[ADMB Users] Application of 'sort' function to variables

kvk fromdustreturned at gmail.com
Wed Apr 21 16:17:31 PDT 2010


Is the 'sort' function applicable to matrices/vectors of variables in
addition to set values? I am encountering problems in doing so.

This small test file works fine, as the 'sort' command is applied to a
matrix drawn from the DAT file:

DATA_SECTION
  init_int nsp;
  init_matrix phases(1,nsp,1,nsp);

PARAMETER_SECTION
  objective_function_value ofv;
  init_number dummy

PROCEDURE_SECTION
  dmatrix phase = phases;
  dmatrix phase_tmp = trans(phase);
  dmatrix test = sort(phase_tmp,1);
  cout<<phase<<endl;
  cout<<phase_tmp<<endl;
  cout<<test<<endl;
  exit(1);

This test file, however, does not, as the 'sort' command is applied to
a matrix of calculated values (first and second lines of the
PROCEDURE_SECTION):

DATA_SECTION
  init_int nsp;
  init_matrix phases(1,nsp,1,nsp);

PARAMETER_SECTION
  objective_function_value ofv;
  init_number dummy
  matrix hold(1,nsp,1,nsp)

PROCEDURE_SECTION
  hold = 2*phases;
  dvar_matrix phase = hold;
  dvar_matrix phase_tmp = trans(phase);
  dvar_matrix test = sort(phase_tmp,1);
  cout<<phase<<endl;
  cout<<phase_tmp<<endl;
  cout<<test<<endl;
  exit(1);

The error message:
"no matching function for call to 'sort(dvar_matrix&,int)' "

When 'dmatrix' is substituted for 'dvar_matrix', the error:
"conversion from 'named_dvar_matrix' to non-scalar type 'dmatrix'
requested"

Am I making an error of syntax or function?

Thank you!

Kray Van Kirk



More information about the Users mailing list