简体   繁体   English

使用LAPACK求解Ax = B,其中x> = 0

[英]Solving Ax=B using LAPACK, where x >= 0

I'm currently working on an iOS app which handles chemical additions to water. 我目前正在开发一个处理水中化学添加物的iOS应用。 In order to find the smallest possible additions, I'm solving Ax=B where A is a 6x6 matrix and B is one column. 为了找到最小的可能加法,我求解Ax = B,其中A是6x6矩阵,B是一列。 As far as I've been reading, LAPACK in the Accelerate Framework is the best way to handle this. 据我所读,加速框架中的LAPACK是处理此问题的最佳方法。 I've been able to get it working for small additions using DGESV_, but larger ones have some negative values for x. 我已经能够使用DGESV_使它适用于少量添加,但是较大的添加对于x具有负值。 This is an issue as you can't add a negative amount of a chemical. 这是一个问题,因为您不能添加负量的化学药品。

So what I need to know is whether there is a function in LAPACK that will allow me to find the minimum solution to Ax=B, where x is always greater than or equal to 0? 所以我需要知道的是,LAPACK中是否有一个函数可以让我找到Ax = B的最小解,其中x始终大于或等于0? If not, is there an alternative solution (other than doing the math myself)? 如果不是,是否有替代解决方案(除了自己做数学之外)?

Thank you 谢谢

Unless A is rank deficient, the solution of Ax = B with A square is unique. 除非A是秩不足的,否则Ax = B且A平方的解是唯一的。 So there is no way to get rid of negative components in the answer. 因此,没有办法消除答案中的负面因素。

If you assume A and B might contain errors that cause a negative component but would like to find a "nearby" solution with all non-negative components, then you could cast this as: 如果假设A和B可能包含导致负分量的错误,但想找到所有非负分量的“附近”解决方案,则可以将其强制转换为:

minimize |Ax - b|  subject to x >= 0

This is a quadratic program. 这是一个二次程序。 There are libraries to solve such problems, but LAPACK isn't one of them. 有一些库可以解决此类问题,但是LAPACK并不是其中之一。

Edit 编辑

Your matrix is full rank. 您的矩阵是完整等级。 Wolfram Alpha is very nice for playing with little problems like this. Wolfram Alpha非常适合玩这样的小问题。 Your 6x6 has a determinant of 5x10^11, so it's very nicely conditioned. 您的6x6的行列式为5x10 ^ 11,因此条件非常好。

I'm no expert on QP, but this one has special structure. 我不是QP专家,但是这个人有特殊的结构。 For standard form (see Wikipedia for notation ), rewrite as: 对于标准格式(请参阅Wikipedia中的符号 ),重写为:

minimize ( x'(A'A)x + (-2b'A)x )  subject to x >= 0

Here the quadratic coefficient matrix Q = A'A is symmetric positive definite, which (if I am recalling my matrix algebra correctly), makes the system convex and easier to solve: a single global solution is guarenteed. 在这里,二次系数矩阵Q = A'A是对称正定的,(如果我正确地回忆了我的矩阵代数),使系统凸Q = A'A易于求解:保证了单个全局解。 Note c = -2b'A . 注意c = -2b'A

Here is a page of QP libraries , some in C, and some optimized for the convex case. 这是QP库的页面 ,有些使用C语言,有些针对凸情况进行了优化。 Perhaps one of them will work for you. 也许其中之一会为您工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用BLAS或LAPACK与Xcode - Using BLAS or LAPACK with Xcode 需要x上升到b的上标 - Need a superscript for x raise to b 在Objective-C中使用DDMathParser求解数学 - Solving math using DDMathParser in Objective-C 什么是 _convertNSDictionaryToDictionary<A, B where ...> (NSDictionary?)-&gt; [A : B] 为什么它会导致我的应用程序崩溃? - What is _convertNSDictionaryToDictionary<A, B where ...> (NSDictionary?) -> [A : B] and why is it crashing my app? 在哪里可以找到使用Apple新UI的OS X应用程序的源代码框架? - Where can I find a source code skeleton for an OS X app using Apple's new UI? &lt;__ NSCFSet:0x74957b0&gt;在枚举时发生了突变 - <__NSCFSet: 0x74957b0> was mutated while being enumerated &#39;NSInvalidArgumentException&#39;,原因:&#39;-[UIImage length]:无法识别的选择器发送到实例0x1d53b6b0&#39; - 'NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance 0x1d53b6b0' 接收器( <MyQueryTableController: 0x9b7e9b0> )没有标识符为“ test”的搜索…等等 - Receiver (<MyQueryTableController: 0x9b7e9b0>) has no segue with identifier 'test''…and more 采集 <NSCFSet: 0x1b0b30> 在被列举时被突变。 如何确定哪一套? - Collection <NSCFSet: 0x1b0b30> was mutated while being enumerated. How to determine which set? 为什么在Objective-C中我不能在方法a()中调用方法b(),其中a和b在一个接口中 - Why in Objective-C I can't invoke method b() in method a(), where a and b are in one interface
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM