问题
I have a system of linear equations with dimensions 3xN that I am currently solving using the Accord.NET method:
double[,] A = ... // matrix A
double[] b = ... // vector b
// Then all that is necessary is to call:
double[] x = A.Solve(b, leastSquares: true);
This works fine but I need to also impose constraints (primarily, x > 0). Is there a way to implement this (ideally within Accord or some other simple library)?
The elements of both A and B can have positive, negative and zero values and I can't think of any particular patterns that could be used to simplify the problem (e.g. diagonal values, singularity). The solution needs to be computationally fast and simple but doesn't necessarily need to give an exact answer (i.e. it could be numerically solved if that's faster).
On a side note, if the solver were to be made 'less exact' while still providing an accurate solution, is there a way to add a preference such as:
- minimising the values of all x elements
- minimising the number of x elements that are non-zero
Thanks!
来源:https://stackoverflow.com/questions/56519307/solving-a-system-of-linear-equations-with-constraints-in-c-sharp-mono