Difference between mldivide and lsqr
    4 views (last 30 days)
  
       Show older comments
    
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.
0 Comments
Accepted Answer
  Bruno Luong
      
      
 on 21 Jul 2023
        
      Edited: Bruno Luong
      
      
 on 21 Jul 2023
  
      A=rand(3,5)
b=rand(3,1)
The backslash  returns a solution with most 0s and lsqr returns solution with minimum l2-norm.
xbackslash=A\b
xlsqr=lsqr(A,b)
xminnorm=lsqminnorm(A,b)
A*xbackslash
A*xlsqr
norm(xbackslash)
norm(xlsqr) % smaller even xlsqr has no O
On the runtime the backslash is usualy faster, at least for dense matrix.
0 Comments
More Answers (0)
See Also
Categories
				Find more on Special Functions in Help Center and File Exchange
			
	Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
