简体   繁体   中英

pinv result diff - matlab

As part of our homework we need to map imageA into iamge B
I'm using this code for inverse mapping
A = zeros(8,8);
A = [imageB(1,1) imageB(2,1) 0 0 1 0 (-1)*(imageB(1,1)) imageA(1,1) (-1) (imageB(2,1)) imageA(1,1);
0 0 imageB(1,1) imageB(2,1) 0 1 (-1)
(imageB(1,1)) imageA(2,1) (-1) (imageB(2,1)) imageA(2,1);
imageB(1,2) imageB(2,2) 0 0 1 0 (-1)
(imageB(1,2)) imageA(1,2) (-1) (imageB(2,2)) imageA(1,2);
0 0 imageB(1,2) imageB(2,2) 0 1 (-1)
(imageB(1,2)) imageA(2,2) (-1) (imageB(2,2)) imageA(2,2);
imageB(1,3) imageB(2,3) 0 0 1 0 (-1)
(imageB(1,3)) imageA(1,3) (-1) (imageB(2,3)) imageA(1,3);
0 0 imageB(1,3) imageB(2,3) 0 1 (-1)
(imageB(1,3)) imageA(2,3) (-1) (imageB(2,3)) imageA(2,3);
imageB(1,4) imageB(2,4) 0 0 1 0 (-1)
(imageB(1,4)) imageA(1,4) (-1) (imageB(2,4)) imageA(1,4);
0 0 imageB(1,4) imageB(2,4) 0 1 (-1)
(imageB(1,4)) imageA(2,4) (-1) (imageB(2,4))*imageA(2,4)];
imageA(1,4); imageA(2,4)];
B = reshape(imageA,[],1);

D = pinv(A)*B;


my friend however uses this code :
D = inv(A'*A)*A'*B;


i get the same values as he does except i get 0.0000 and he get -0.0000 all the rest of the numbers positive or negative are the same.

why is this ? and what is the correct answer?
what do you suggest i can do in order to check my results easly?

It seems like these differences stem from numerical instabilities. How big are they with respect to machine precision ( eps )? Why don't you use backslash ?

>> D = A \ B;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM