I had a matrix D which is m*n and i am calculating the pseudo inverse using the formula inv(D'*D)*D' but it is not generating the same result as pinv(D).I need the term inv(D'*D) which i require for incremental operation. My all accuracy depends upon inv(D'*D) which is not correct. Is there any alternate way to get inv(D'*D) accurately? can any one help me please?
% D is 3x4 matrix that i had copied from one blog just for demonstration purpose. Actually original one of mine also had same problem bu its size is too large that i can't post it here.
D = -[1/sqrt(2) 1 1/sqrt(2) 0;0 1/sqrt(2) 1 1/sqrt(2);-1/sqrt(2) 0 1/sqrt(2) 1];
B1 = pinv(D)
B2 = D'*inv(D*D')
B1 =
-0.353553390593274 0.000000000000000 0.353553390593274
-0.375000000000000 -0.176776695296637 0.125000000000000
-0.176776695296637 -0.250000000000000 -0.176776695296637
0.125000000000000 -0.176776695296637 -0.375000000000000
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =
1.904842e-017.
B2 =
-0.250000000000000 0 0.500000000000000
-0.500000000000000 0 0
0.250000000000000 -0.500000000000000 0
0 0 -0.750000000000000
I need inv(D'D) to do incremental operation. Actually in my problem at step 1, each time a new row will be added to the last position of D and in step 2 first row of the D will be removed. So i want to find final D inverse using the inverse which i calculated before these two steps. More precisely have a look here:
B = inv(D'*D); % if i can calculate it accurately then further work is as follows
D1 = [D;Lr]; %Lr is last row to be added
BLr = B-((B*Lr'*Lr*B)/(1+Lr*B*Lr')); % Row addition formula
Fr = D1(1,:); % First row to be removed
D2 = removerows(D1,1);
BFr = BLr+ ((BLr*Fr'*Fr*BLr)/(1-Fr*BLr*Fr')); % row deletion formula
B = BFr;
Y = BFr*D2;
解决方案
The formulae (D^T D)^-1 D^T or D^T (D D^T)^-1 you are using for the Moore-Penrose pseudoinverse are only valid if D has full column or full row rank, respectively.
This is not true in your case, as the warning "Matrix is close to singular" shows.
The matlab pinv command works for arbitrary D, even if the matrix has neither full row or full column rank.