How to use least squares method in Matlab?

后端 未结 3 940
無奈伤痛
無奈伤痛 2020-12-21 06:46

I have 37 linear equations and 36 variables in the form of a matrix equation; A*X=B . The equations don\'t have an exact answer. I want to use Matlab least square method to

相关标签:
3条回答
  • 2020-12-21 07:16

    The most general way to solve this is to use the pseudoinverse:

    X = pinv(A) * B;
    
    0 讨论(0)
  • 2020-12-21 07:25

    You can calculate x by:

    x = (A'*A)\A'*B

    0 讨论(0)
  • 2020-12-21 07:31

    If A is of full rank, i.e. the columns of A are linearly independent, the least-squares solution of an overdetermined system of linear equations

    A * x = b
    

    can be found by inverting the normal equations (see Linear Least Squares):

    x = inv(A' * A) * A' * b
    

    If A is not of full rank, A' * A is not invertible. Instead, one can use the pseudoinverse of A

    x = pinv(A) * b
    

    or Matlab's left-division operator

    x = A \ b
    

    Both give the same solution, but the left division is more computationally efficient.

    The two latter computation methods can also deal with underdetermined systems of linear equations, but they give different solutions in that case: The pseudoinverse gives the solution where x has the smallest sum of squares, while the left-division operator gives a solution with as many 0 coefficients as possible.

    0 讨论(0)
提交回复
热议问题