Solving a System of Linear Equations with Constraints in C# (Mono)

最后都变了- 提交于 2019-12-25 02:23:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!