LSQR method for solving a linear equation with positive value constraint for one column of the solution

258 Views Asked by At

I am solving an overdetermined sparse linear problem (Ax= B) using a C code. The code is using the LSQR method to find the solutions. There are 6 unknowns for every equation. One of the solutions is a one-dimensional array with the type of double, which I don’t want to be negative during the solving process. I found it out about lsqnonneng in Matlab, which solves for non-negative solution. But, I only want one of the columns to be non-negative, and other columns can be negative or positive. Is there any way or any code that can solve it?

1

There are 1 best solutions below

2
On BEST ANSWER

One way to use lsqnonneg to solve this problem is to write each unrestricted variable $x_{i}$ as the difference of two nonnegative variables $x_{i}=u_{i}-v_{i}$. This will roughly double the number of variables and the size of the matrix.

For example, suppose you want a least-squares solution to

$x_{1}+x_{2}+x_{3}=4$

$2x_{1}-x_{2}+x_{3}=5$

$-x_{1}+x_{2}-x_{3}=-1$

$-2x_{1}-3x_{2}+x_{3}=0$

$x_{1} \geq 0$

$x_{2}, x_{3} \; \mbox{unrestricted}$

You can write this as

$x_{1}+u_{2}-v_{2}+u_{3}-v_{3}=4$

$2x_{1}-u_{2}+v_{2} + u_{3}-v_{3}=5$

$-x_{1}+u_{2}-v_{2}-u_{3}+v_{3}=-1$

$-2x_{1}-3u_{2}+3v_{2} + u_{3}-v_{3}=0$

$x_{1}, u_{2}, v_{2}, u_{3}, v_{3} \geq 0$

This can be written in matrix form as

$Az=b$

$z \geq 0$

where

$z=\left[ \begin{array}{c} x_{1} \\ u_{2} \\ v_{2} \\ u_{3} \\ v_{3} \\ \end{array} \right]$

Once you've used lsqnonneg to find the nonnegative least-sqaures solution, you can recover $x_{2}=u_{2}-v_{2}$ and $x_{3}=u_{3}-v_{3}$.