# 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.?

edit retag close merge delete

Sort by » oldest newest most voted There is a handy function for this, the solve function.

solve(A, b, x, DECOMP_SVD);

more

X = 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.?

SVD 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.

Official site

GitHub

Wiki

Documentation