Mercurial > hg > ddm
view pinv_2_fast.m @ 2:e2b116f3b69b
fixed reallocate and pinv_2_fast to work on Octave
added short example very quickly, might not be working properly
author | smusevic |
---|---|
date | Thu, 25 Jul 2013 13:07:07 +0100 |
parents | |
children |
line wrap: on
line source
function xx = pinv_2_fast(A,b,Q,N) b_mat = repmat(reshape(b,[Q,1,1,N]),[1 Q-1 2 1]); AA = zeros(Q,(Q-1),2,N); A1= zeros(Q,(Q-1),2,N); vct_idx = 1:Q; for q=1:Q vct_Q = vct_idx([1:q-1,q+1:Q]); A1(q,:,1,:) = shiftdim(A(vct_Q, 2,:),-1); AA(q,:,1,:) = repmat(A(q,1,:),(Q-1),1) .* A(vct_Q,2,:); A1(q,:,2,:) = A(vct_idx([1:q-1,q+1:Q]), 1,:); AA(q,:,2,:) = repmat(A(q,2,:),(Q-1),1) .* A(vct_Q,1,:); end A2 = (cat(3,conj(AA(:,:,1,:)-AA(:,:,2,:)) .* A1(:,:,1,:),conj(AA(:,:,1,:) - AA(:,:,2,:)) .* A1(:,:,2,:))); A3 = shiftdim(sum(sum(AA(:,:,2,:) .* conj(AA(:,:,1,:)-AA(:,:,2,:)))),3); A_nrm = [-A3, A3]; xx = shiftdim(sum(sum(A2 .* b_mat)), 2).' ./ A_nrm;