Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factorization based solvers returning trivial result for least square solve #531

Open
vpuri3 opened this issue Aug 22, 2024 · 2 comments
Open
Labels
bug Something isn't working

Comments

@vpuri3
Copy link
Member

vpuri3 commented Aug 22, 2024

using LinearAlgebra, LinearSolve

A = rand(10, 4) # tall and skinny system
A[:, 1] .= 0    # A has a column with all zeros
f = rand(10)    # RHS

prob1 = LinearProblem(A, f)           # tall and skinny system
prob2 = LinearProblem(A' * A, A' * f) # square singular system (has a row and a column of all zeros)

sol_df = solve(prob1)                    # [0.0, 0.0, 0.0, 0.0]
sol_lu = solve(prob1, LUFactorization()) # [0.0, 0.0, 0.0, 0.0]
sol_qr = solve(prob1, QRFactorization()) # [0.0, 0.0, 0.0, 0.0]
sol_gm = solve(prob2, SimpleGMRES())     # [0.0, -0.4916139636428349, 0.44349181143744504, 0.7631772710700259]
A \ f                                    # [0.0, -0.4916139636428351, 0.44349181143744565, 0.7631772710700254]

sol_df.retcode # ReturnCode.Failure = 9
sol_lu.retcode # ReturnCode.Failure = 9
sol_qr.retcode # ReturnCode.Failure = 9
sol_gm.retcode # ReturnCode.Success = 1
@vpuri3 vpuri3 added the bug Something isn't working label Aug 22, 2024
@vpuri3 vpuri3 changed the title QRFactorization returning trivial result for least square solve Factorization based solvers returning trivial result for least square solve Aug 22, 2024
@vpuri3
Copy link
Member Author

vpuri3 commented Aug 22, 2024

Come to think about it, I shouldn't be surprised that factorizations fail for rank-deficient/singular matrices. Better to use Krylov methods and get a non-unique solution

@ChrisRackauckas
Copy link
Member

QR you probably just need to turn on pivoting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants