2

I try to repeat the example of calculation of pseudo inverse matrix from lectures:

enter image description here

I use this code

from numpy import *
# https://classes.soe.ucsc.edu/cmps290c/Spring04/paps/lls.pdf
x = np.array([[-11, 2],[2, 3],[2, -1]]) 
print(x)
# computing the inverse using pinv
a = linalg.pinv(x)
print(a)

My result of the calculation differs from the result in the lecture.

My result:

[[-0.07962213  0.05533063  0.00674764]
 [ 0.04048583  0.2854251  -0.06275304]]

The result form lecture:

[[-0.148  0.180  0.246]
 [ 0.164  0.189 -0.107]]

What am I doing wrong? Tell me please!

V. Gai
  • 450
  • 3
  • 9
  • 30

1 Answers1

2

There is a mistake in the lecture notes. It appears that they found the pseudo-inverse of

    [-1   2]
A = [ 2   3]
    [ 2  -1]

(Note the change of A[0,0] from -11 to -1.) Here's the calculation with that version of A:

In [73]: A = np.array([[-1, 2], [2, 3], [2, -1]]) 

In [74]: A
Out[74]: 
array([[-1,  2],
       [ 2,  3],
       [ 2, -1]])

In [75]: np.linalg.pinv(A)
Out[75]: 
array([[-0.14754098,  0.18032787,  0.24590164],
       [ 0.16393443,  0.18852459, -0.10655738]])

In [76]: np.linalg.pinv(A).dot([0, 7, 5])
Out[76]: array([ 2.49180328,  0.78688525])
Warren Weckesser
  • 110,654
  • 19
  • 194
  • 214