如何在Matlab中使用最小二乘法? [英] How to use least squares method in Matlab?
问题描述
我有37个线性方程和36个矩阵方程形式的变量; A * X = B.这些方程式没有确切的答案.我想使用Matlab最小二乘方法找到错误最少的答案.我是Matlab的新手,所以任何评论都将对您有所帮助.谢谢
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 find the answers with the least error. I am new to Matlab so any comments will help. Thank you
推荐答案
如果A
具有完整等级,即A
的列是线性独立的,则超定线性方程组的最小二乘解
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
如果A
的等级不完整,则A' * A
不可逆.相反,可以使用A
If A
is not of full rank, A' * A
is not invertible. Instead, one can use the pseudoinverse of A
x = pinv(A) * b
或Matlab的左分区运算符
or Matlab's left-division operator
x = A \ b
两者都提供相同的解决方案,但左除法的计算效率更高.
Both give the same solution, but the left division is more computationally efficient.
后两种计算方法也可以在确定的线性方程组下处理,但是在那种情况下它们给出不同的解:伪逆给出x
的平方和最小的解. ,而左除运算符则给出了一个尽可能多的0系数的解决方案.
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.
这篇关于如何在Matlab中使用最小二乘法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!