0
$\begingroup$

I have the following problem to solve:

Ax = b where A is singular.

To resolve this I introduce a condition Cx = d

Even after this, I am not able to solve it using scipy.optimize.minimize as it keeps complaining that the matrix is singular. I am trying to solve it using the following:

optimum_func = lambda x: np.sum((Ax -b)**2) constraint = ({'type': 'eq', 'func': lambda x: C@x-d})

What is the right way to solve this problem? And what theory did I miss that it does not work? Please ask for any other information needed and I will edit this post with information.

$\endgroup$
3
  • $\begingroup$ Does $Ax = b$ even have a solution? $\endgroup$ Mar 29 '19 at 19:30
  • $\begingroup$ in the least square sense, I am pretty sure it does. $\endgroup$
    – manav
    Mar 30 '19 at 12:00
  • $\begingroup$ What if $A x = b$ has infinitely many solutions? Then you're solving the wrong problem. $\endgroup$ Mar 30 '19 at 12:09
0
$\begingroup$

You can use the Moore–Penrose inverse (the pseudoinverse) to get a solution. In this example, the system is over-determined (has infinitely many solutions) and the pseudo-inverse leads to the least-squares solution.

import numpy as np
A = np.array([[3, 4], [6, 8]])
b = np.array([[15], [30]])
# Compute the pseudo inverse and solve
Apinv = np.linalg.pinv(A)
x = Apinv @ x
x
#> array([[1.8],
#>       [2.4]])
# Check that A*x = b
A @ x
#> array([[15.],
#>       [30.]])

# Or find the least squares solution
soln = np.linalg.lstsq(A, b)
x = soln[0]
x
#> array([[1.8],
#>       [2.4]])
A @ x
#> array([[15.],
#>       [30.]])
```
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.