OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sun, 04 Jun 2017 18:23:05 -0500What is best practice to solve least square problem AX = Bhttp://answers.opencv.org/question/156394/what-is-best-practice-to-solve-least-square-problem-ax-b/ Hi, i have a system of linear equations AX = B where A is 76800x6, B is 76800x1 and we have to find X, which is 6x1. I was using X = invert(AT* A) AT* B where AT is transpose of A. But i want to increase the speed of operation and also it dose not protect my calculation under singularity conditions. Is there any faster way to do this.?Sat, 03 Jun 2017 16:17:37 -0500http://answers.opencv.org/question/156394/what-is-best-practice-to-solve-least-square-problem-ax-b/Answer by Tetragramm for <p>Hi, i have a system of linear equations AX = B where A is 76800x6, B is 76800x1 and we have to find X, which is 6x1. I was using X = invert(AT* A) AT* B where AT is transpose of A. But i want to increase the speed of operation and also it dose not protect my calculation under singularity conditions. Is there any faster way to do this.?</p>
http://answers.opencv.org/question/156394/what-is-best-practice-to-solve-least-square-problem-ax-b/?answer=156449#post-id-156449There is a handy function for this, the [solve](http://docs.opencv.org/master/d2/de8/group__core__array.html#ga12b43690dbd31fed96f213eefead2373) function.
solve(A, b, x, DECOMP_SVD);Sat, 03 Jun 2017 22:22:10 -0500http://answers.opencv.org/question/156394/what-is-best-practice-to-solve-least-square-problem-ax-b/?answer=156449#post-id-156449Comment by Tetragramm for <p>There is a handy function for this, the <a href="http://docs.opencv.org/master/d2/de8/group__core__array.html#ga12b43690dbd31fed96f213eefead2373">solve</a> function.</p>
<pre><code>solve(A, b, x, DECOMP_SVD);
</code></pre>
http://answers.opencv.org/question/156394/what-is-best-practice-to-solve-least-square-problem-ax-b/?comment=156589#post-id-156589SVD is the most stable version, with the ability to check singularity ect. Try DECOMP_NORMAL for speed.
Alternatively, may I suggest using a specialized matrix math library like Eigen? Then you can use whatever decomposition you need with whatever properties you desire. And it might very well be faster.Sun, 04 Jun 2017 18:23:05 -0500http://answers.opencv.org/question/156394/what-is-best-practice-to-solve-least-square-problem-ax-b/?comment=156589#post-id-156589Comment by UsmanArif for <p>There is a handy function for this, the <a href="http://docs.opencv.org/master/d2/de8/group__core__array.html#ga12b43690dbd31fed96f213eefead2373">solve</a> function.</p>
<pre><code>solve(A, b, x, DECOMP_SVD);
</code></pre>
http://answers.opencv.org/question/156394/what-is-best-practice-to-solve-least-square-problem-ax-b/?comment=156462#post-id-156462X = invert(AT* A) AT* B is taking 4 min and 37 sec while solve is taking 8 min and 34 secs for a video on which i am working. Is there any thing more fast.?Sun, 04 Jun 2017 00:12:11 -0500http://answers.opencv.org/question/156394/what-is-best-practice-to-solve-least-square-problem-ax-b/?comment=156462#post-id-156462