I have two matrices B and D, where B is a matrix and D is a matrix defined as follows:
with ,
where is the identity matrix and denotes the Kronecker product of matrices P and Q. I am currently computing B as a sparse matrix as follows:
o = ones(n,1);z = zeros(n,1);D = spdiags([-o o z],-1:1,n,n);D(1,1) = 0;I = speye(n);B1 = kron(I, D);B2 = kron(D, I);B = [B1;B2];
I know that can be quickly computed using
[0; diff(x)]
I need to find a quick way of computing and in a similar manor. Currently my code is spending a signifigant amount of its time to compute and so I was wondering if anyone had some incite into computing this efficently.
Best Answer