2

I am trying to simulate a signal and need to solve the matrix equation Ax = B. Here A and B are both known: A is 500x40 matrix (40 signal source candidates), B is a 500x1 vector (my target signal), and x is the 40x1 vector I am looking for (coefficients).

I have found the function numpy.linalg.lstsq. However I have certain boundary restrictions in this case:

  1. all the elements of x must be positive;
  2. there are 5 characteristic peaks in the target signal that need to be fixed, in other words, 5 particular elements of the final product A*x must be the same with B.

How can I first apply the boundary conditions and then find the solution with least square? Shall I keep using numpy.linalg.lstsq or another function? I am clueless right now and would really appreciate your help.

Thanks a lot in advance!

Somi

somnious
  • 21
  • 1
  • 1
    The requirement that `x` be positive can be addressed by non-negative least-squares: [`scipy.optimize.nnls`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.nnls.html) can handle this (as can `scipy.optimize.lsq_linear`, as mentioned in that document). As to your other requirement, do you mean five *specific* entries of `A * x` have to match `B` or *any* five entries? – Ahmed Fasih Feb 16 '20 at 04:40
  • Hi Ahmed, thanks for the comment! Five specific entries of A*x have to match B. The index is known. – somnious Feb 18 '20 at 07:11

0 Answers0