Behaviour of backslash operator for non-square matrices least-squares fitting

조회 수: 2 (최근 30일)
I am currently trying to reproduce a set of results from a pre-existing project and can't get to the bottom of the following difference.
Phi = design matrix of input data size(29507x97)
Ref = reference values to fit to, six data sets, size(29507x6)
Phi = rand(29507,97);
Ref = rand(29507,6);
c1 = Phi\Ref;
for ii = 1:6
c2(:,ii) = Phi\Ref(:,ii);
end
all(all(c1==c2))
I would have expected c1 to give identical results to c2. I can't find detailed information on what the "\" algorithm is doing differently between these case.
Any help appreciated!

채택된 답변

the cyclist
the cyclist 2020년 2월 24일
They are equal, to within floating-point precision. Notice that
max(abs(c1(:)-c2(:)))
is around 1e-16.
  댓글 수: 4
Matt J
Matt J 2020년 2월 24일
편집: Matt J 2020년 2월 24일
Also, internal parallelization of mldivide and other linear algebra operations is different depending on the size of the inputs. So, when you perform the mldivide column-by-column, the inputs are divided up into parallel chunks in a different way, leading to floating point differences.
Matt O'Donnell
Matt O'Donnell 2020년 2월 24일
@the cyclist Yes. I agree with that as the likely root cause.
I thought it would be doing the same least squares calculation on a column by column basis as each column should be treated independently from each other in terms of doing the expected calculation.i.e. column 1 should never know anything about the other 5 columns's calculations mathematically speaking. But as @Matt J has suggested it is doing something across the columns, or even splitting each column differently, which leads to the difference/calculation order effect as suggested.
Many thanks to both of you for helping to get my head around this.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by