필터 지우기
필터 지우기

Difference between mldivide and lsqr

조회 수: 14 (최근 30일)
Jaehoon Jeong
Jaehoon Jeong 2023년 7월 21일
편집: Bruno Luong 2023년 7월 21일
Hi, I am curious about the difference between mldivide and lsqr.
Both seem to be used for calculating x where A*x=b.
Thank you in advance.

채택된 답변

Bruno Luong
Bruno Luong 2023년 7월 21일
편집: Bruno Luong 2023년 7월 21일
The difference manifests obviously when you try to solve underdetermined linear system A*x = b.
A=rand(3,5)
A = 3×5
0.1391 0.7822 0.5816 0.3031 0.3500 0.4841 0.6309 0.9509 0.7327 0.0768 0.7137 0.8771 0.4724 0.4694 0.4100
b=rand(3,1)
b = 3×1
0.9778 0.2986 0.9737
The backslash returns a solution with most 0s and lsqr returns solution with minimum l2-norm.
xbackslash=A\b
xbackslash = 5×1
-0.4389 1.8328 -0.6786 0 0
xlsqr=lsqr(A,b)
lsqr converged at iteration 3 to a solution with relative residual 8.3e-14.
xlsqr = 5×1
-0.1969 1.1213 -0.1120 -0.3746 0.8767
xminnorm=lsqminnorm(A,b)
xminnorm = 5×1
-0.1969 1.1213 -0.1120 -0.3746 0.8767
Both minimize norm(A*x-b,2), in case not overdetermined system A*x match b (as withe example here)
A*xbackslash
ans = 3×1
0.9778 0.2986 0.9737
A*xlsqr
ans = 3×1
0.9778 0.2986 0.9737
norm(xbackslash)
ans = 2.0031
norm(xlsqr) % smaller even xlsqr has no O
ans = 1.4891
On the runtime the backslash is usualy faster, at least for dense matrix.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by