The leastsquares command finds an approximate solution to A*X = B that minimizes the sum of squares of the errors. If the matrix A is not full rank then null is returned. B can be a matrix or a vector.
A = [[1,2],[3,4],[5,6]]; B = [7,8,9]; leastsquares(A,B); [-6, 13/2]