Numerical errors in Julia Package?

Hello,
I have noticed a strange behavior after updating the Julia package recently.
With the latest julia version of the Manjaro stable branch, if I run the following code for solving least squares:

using LinearAlgebra
m,n=100,14
t = [ i/(m-1) for i in 0:(m-1)]
A = [tau^j for tau in t, j in 0:n]
magic=2006.7874531048527;
y=exp.(sin.(4*t))/magic;
Q,R = qr(A);
x = R\(Q[:,1:size(A,2)]'*y)

I get

15-element Vector{Float64}:
[Some numerical values...]
    1297.8034058697126

On the other hand, if i do the same on a version downloaded from the Julialang website (julia-1.7.2-linux-x86_64.tar.gz) (which is the exact same Julia version number as the one in the Manjaro package), I get

15-element Vector{Float64}:
[Some numerical values...]
   1.0000001533225875

which is the correct solution (as it is known analytically that the last entry of the solution is 1).

So, it seems that the version provided with Manjaro yields more numerical errors. I have also experienced this behavior on other operations (Cholesky factorization, etc…). Does anybody have any explanation of this?

Thanks!

My configuration:

  • CPU: Intel Core i7-1065G7,
  • Kernel 5.10.98-1-MANJARO (Manjaro stable),
  • julia package 2:1.7.2-1,

This is a sync package from Arch repo.

It was last updated on 2022-02-21 epoch2 v1.7.2-2

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.7.2 (2022-02-06)
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |

julia> using LinearAlgebra

julia> m,n=100,14
(100, 14)

julia> t = [ i/(m-1) for i in 0:(m-1)]
100-element Vector{Float64}:
 0.0
 0.010101010101010102
 0.020202020202020204
 0.030303030303030304
 0.04040404040404041
 0.050505050505050504
 0.06060606060606061
 0.0707070707070707
 0.08080808080808081
 0.09090909090909091
 0.10101010101010101
 0.1111111111111111
 0.12121212121212122
 ⋮
 0.8888888888888888
 0.898989898989899
 0.9090909090909091
 0.9191919191919192
 0.9292929292929293
 0.9393939393939394
 0.9494949494949495
 0.9595959595959596
 0.9696969696969697
 0.9797979797979798
 0.98989898989899
 1.0

julia> A = [tau^j for tau in t, j in 0:n]
100×15 Matrix{Float64}:
 1.0  0.0        0.0          0.0          0.0          …  0.0          0.0          0.0          0.0
 1.0  0.010101   0.00010203   1.03061e-6   1.04102e-8      1.1169e-22   1.12818e-24  1.13957e-26  1.15108e-28
 1.0  0.020202   0.000408122  8.24488e-6   1.66563e-7      2.2874e-19   4.62102e-21  9.33539e-23  1.88594e-24
 1.0  0.030303   0.000918274  2.78265e-5   8.43226e-7      1.97855e-17  5.9956e-19   1.81685e-20  5.5056e-22
 1.0  0.040404   0.00163249   6.5959e-5    2.66501e-6      4.6846e-16   1.89277e-17  7.64755e-19  3.08992e-20
 1.0  0.0505051  0.00255076   0.000128826  6.50638e-6   …  5.4536e-15   2.75434e-16  1.39108e-17  7.02566e-19
 1.0  0.0606061  0.00367309   0.000222612  1.34916e-5      4.05207e-14  2.4558e-15   1.48836e-16  9.02038e-18
 1.0  0.0707071  0.00499949   0.000353499  2.49949e-5      2.20847e-13  1.56154e-14  1.10412e-15  7.80692e-17
 1.0  0.0808081  0.00652995   0.000527672  4.26402e-5      9.59407e-13  7.75278e-14  6.26487e-15  5.06252e-16
 1.0  0.0909091  0.00826446   0.000751315  6.83013e-5      3.50494e-12  3.18631e-13  2.89664e-14  2.63331e-15
 1.0  0.10101    0.010203     0.00103061   0.000104102  …  1.1169e-11   1.12818e-12  1.13957e-13  1.15108e-14
 1.0  0.111111   0.0123457    0.00137174   0.000152416     3.18664e-11  3.54071e-12  3.93412e-13  4.37124e-14
 1.0  0.121212   0.0146924    0.00178089   0.000215866     8.29863e-11  1.00589e-11  1.21927e-12  1.4779e-13
 ⋮                                                      ⋱                                         
 1.0  0.888889   0.790123     0.702332     0.624295        0.27373      0.243315     0.21628      0.192249
 1.0  0.89899    0.808183     0.726548     0.65316         0.309958     0.278649     0.250503     0.225199
 1.0  0.909091   0.826446     0.751315     0.683013     …  0.350494     0.318631     0.289664     0.263331
 1.0  0.919192   0.844914     0.776638     0.713879        0.395793     0.36381      0.334411     0.307388
 1.0  0.929293   0.863585     0.802524     0.74578         0.446354     0.414793     0.385464     0.358209
 1.0  0.939394   0.882461     0.828978     0.778737        0.502719     0.472251     0.44363      0.416743
 1.0  0.949495   0.901541     0.856008     0.812776        0.565483     0.536923     0.509806     0.484058
 1.0  0.959596   0.920824     0.883619     0.847918     …  0.635291     0.609622     0.584991     0.561355
 1.0  0.969697   0.940312     0.911818     0.884187        0.712847     0.691246     0.670299     0.649987
 1.0  0.979798   0.960004     0.94061      0.921608        0.798918     0.782778     0.766964     0.75147
 1.0  0.989899   0.9799       0.970002     0.960204        0.894334     0.8853       0.876358     0.867506
 1.0  1.0        1.0          1.0          1.0             1.0          1.0          1.0          1.0

julia> magic=2006.7874531048527;

julia> y=exp.(sin.(4*t))/magic;

julia> Q,R = qr(A);

julia> x = R\(Q[:,1:size(A,2)]'*y)
15-element Vector{Float64}:
   0.0004983151685235319
   0.0019899844279268786
   0.0042128704771148325
  -0.006236968547994574
   0.07434877716958352
  -0.8184198703622808
   4.385806911859523
 -16.417021607549707
  42.446684448139415
 -73.54081667380801
  84.72882079897417
 -64.10938507389506
  30.631176100980912
  -8.381424477628508
   1.000000249382658
1 Like

Can’t reproduce it with julia 1.7.2 (2022-02-06) (package 2:1.7.2-2). The version 2:1.7.2-2 is in stable, so you are not up to date.

$ cat test.jl 
using LinearAlgebra
m,n=100,14
t = [ i/(m-1) for i in 0:(m-1)]
A = [tau^j for tau in t, j in 0:n]
magic=2006.7874531048527;
y=exp.(sin.(4*t))/magic;
Q,R = qr(A);
x = R\(Q[:,1:size(A,2)]'*y)
print(x)
$ julia test.jl 
[0.0004983151685235319, 
 0.0019899844279268786, 
 0.0042128704771148325, 
-0.006236968547994574, 
0.07434877716958352, 
-0.8184198703622808, 
4.385806911859523, 
-16.417021607549707, 
42.446684448139415, 
-73.54081667380801, 
84.72882079897417, 
-64.10938507389506, 
30.631176100980912, 
-8.381424477628508, 
1.000000249382658]

(Added the newlines my self)

1 Like

@xabbu @linux-aarhus ,
Many thanks for your answers! Indeed, I have updated the Julia package to 2:1.7.2-2, and now I get

15-element Vector{Float64}:
   0.0004983151685225632
   0.001989984431559031
   0.00421287030051599
  -0.006236964961106366
   0.07434873710404868
  -0.8184195923094356
   4.385805629349877
 -16.417017518022305
  42.446675237834555
 -73.5408019144801
  84.72880407676679
 -64.10937198771387
  30.631169374330916
  -8.381422434673267
   0.9999999716615636

which is the correct answer (it corresponds to the solution obtained by using the SVD).
Problem solved… thanks!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.