Hi, I’m trying to use a simple OLS solution to an overdetermined linear system using MKL and LinearAlgebra, with coefficient matrix

‘’’

M = [200000 0 0 (2e5)^2 0; 0 0 0 0 0; 0 0 0 0 0; 0 0 0 0 0; 0 2e5 0 0 (2e5)^2; 0 0 3e5 0 (3e5)^2]

‘’’

and observation

‘’’

y = [2e5 0 0 0 4e5 9e5]

‘’’

When I try to get the ols solution of the system with

‘’’

(M’ * M)^(-1) * M’ * y’

‘’’

the output is

‘’’

5×1 Matrix{Float64}:

1.9780612128670327

3.969978473845913

2.0318402149168833

9.652545605920437e-6

5.091301176166074e-6

‘’’

but this is incorrect. In particular, if I first store the result

‘’’

u = (M’ * M)^(-1) * M’

‘’’

and then compute

‘’’

u * y’

‘’’

the output is instead

‘’’

5×1 Matrix{Float64}:

1.3066744941170327

0.645027301970913

1.7964886524168833

1.436876312377322e-5

-5.193294015312655e-6

‘’’

Any pointers on what I am doing wrong/why this is happening?