Thanks Sebastien
we now have all 3*NNZD(2) = 3*119=357 matrix elements and they are NNZD(2) (i.e. the total number of non-zero Hessian elements) apart rather than no-of-vars apart as they used to be.
Is there a reason that M_.NNZDerivatives is 3x3 matrix rather than 3x1 vector, i..e. M_.NNZDerivatives ans = 47 0 0 119 0 0 0 0 0
Best regards George
----- Original Message ----- From: "Sébastien Villemot" sebastien.villemot@ens.fr To: dev@dynare.org Sent: Monday, June 29, 2009 10:31 AM Subject: Re: [DynareDev] 2nd and 3rd model derivatives + k-order
"G. Perendia" george@perendia.orangehome.co.uk a écrit :
- However,
M_.NNZDerivatives(2) ans = 119 should result in a Hessian matrix of 3*119, total 357 elements, however, as can be seen below, it finishes sparse at element 138 instead 357-1=356.Alternatively, if 119 it a total number of elements (including indices) then it should be divisible by 3. Can you explain me where is
this
discrepancy occurring form?
Sorry it was my mistake. The v2 matrix in the C file was not correctly constructed. This should now be fixed.
- Also, in a related issue, if you, or anyone else, has no objections Re
my
previous email, would it be then possible to change the behaviour of the preprocessor and have the indices and values of the sparse Hessian from
the
mex file returned grouped together either 3 by 3 as per my example below (which would then also constitute a 3 column matrix by number of non-zero elements rows as per your email) or, if it is supposed to be a "3 row" matrix, then apart by the total number of non-zero Hessian values, that
is,.
rather than being apart by no-of-vars/equations as it seems to be the case now?
The matrix v2 has 3 columns. In the C file, it is constructed in column major order (which is Fortran and MATLAB's internal representation). For a n-by-3 matrix stored in a vector, the first n elements are the first columns, the next n elements the second, and the last n elements the third.
Put it otherwise, the (i,j) element has index (i-1)+(j-1)*n in the vector.
The other convention is row major order, where element (i,j) has index (j-1)+3*(i-1); we don't use it since it is not MATLAB's internal representation.
Please let me know if you need more explanations or if you discover another bug.
Best,