Open heltonbiker opened 6 years ago
Have you tried solving the underlying optimization problem? From the scipy documentation
Compute least-squares solution to equation Ax = b. Compute a vector x such that the 2-norm |b - A x| is minimized.
I'm sure you can also do this using Math.Net.
Thanks @sebhofer for the input.
I'm a bit confused by your answser. As I understand, the two sentence quoted from scipy.linalg.lstsq
mean the same thing, that is, they are like synonims of one another.
In my python example above, the solution is found performing one step (that is, one single call to lstsq
).
If I test with larger input sizes, the same results are obtained from python and from MathNet with one call to either lstsq
and Solve
, since apparently they are the same thing.
But below a minimum of rows, the python code keeps working, but MathNet doesn't.
I agree that the two sentences are synonymous, I just copied them from the scipy documentation.
But then I disagree. How do you know that Solve
and lstsq
do the same thing? There are many different ways to solve a set of linear equations and many of them won't work on underdetermined systems. I'm assuming that MathNet is trying to use one of the algorithms that can't handle these underdetermined problems. (I have to admit that I don't know MathNet well, so this is speculation.)
My suggestion is: Set up the minimization problem as stated in the scipy documentation and use one of MathNet's minimization routines to solve it. It might not be the same solution as given by scipy, but it should give you one of the many solutions. (Don't forget to check if it actually does solve the original problem!) If you require the exact same solution as the scipy one, you'd need to dig into the scipy source to find out which algorithm (and possibly initial conditions they are using).
I am trying to find out why I can solve a given linear system in python (
scipy.linalg.lstsq
) but not in Mathnet.Here is the python code:
And here is the Mathnet code:
Which gives me this error:
There's an almost identical question in the forums, and the answer makes sense, that is, using a larger number of equations (rows) than variables (columns) to have a determinate system.
But the fact is: the python code not only runs, but it works, resulting in a calibration matrix that actually make my data (force applied to a load cell array) be correct.
So how could I do that in Mathnet the same way I did in python, and why the current form doesn't work?
Also, the error message does not feel quite appropriate for this situation, IMO.