If your data is floating-point then Maple should get this very quickly. If A
, B
, and y
all have only numeric entries then try,
ans := LinearAlgebra:-LeastSquares( evalf(A), evalf(B.y) );
or, if you want the solution which itself has minimal 2-norm,
ans := LinearAlgebra:-LeastSquares( evalf(A), evalf(B.y), 'optimize'=true );
My guess is that your data is purely rational or integer, and that you may not realize that using this will cause Maple to try and find an exact rational answer. Or you might have some unknown symbolic quantity in the data (...though that could make the goal of computing minimal residual problematic). Such purely exact data, whether rational or symbolic, is a potential memory hogging nightmare and likely not at all what you really want in you are considering C++ as an alternative scheme. That is why I wrapped with calls to evalf
, to cast the data to floats.
With purely float data, 36x20 least squares is a tiny problem and Maple should be able to do it in just a fraction of a second.
You should let the LinearAlgebra:-LeastSquares
routine do the lifting, and not try and form or use normal equations or for Matrix inversions yourself. Use the method=SVD
option if you want a robust approach. Let it deal with the numerical difficulties.