Skip to content
Advertisement

Solve a linear system of equations with bounds using LSQR/LSMR SciPy

Question is quite straight forward. I have an overdetermined system I am attempting to use SciPy LSQR (or LSMR) to solve. However, I cannot find anywhere in the docs on how to set restraints for the minimization.

E.G. Let’s say this is the output:

JavaScript

We can see the solution arrive to -0.1, which is great. However, I’d like to set bounds such that x(1) >= 0. Therefore, the iteration would stop when x(1) = 0.27. I cannot find anywhere on the documentation: https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.lsqr.html regarding how to do this.

Any help would greatly be appreciated!

Advertisement

Answer

The functions lsqr and lsmr in scipy.sparse.linalg do not have options for adding constraints. You might be able to use scipy.optimize.lsq_linear instead.

Advertisement