How do I use the least squares approximation in MATLAB?

夙愿已清 提交于 2019-12-01 18:01:58

mldivide, ("\") actually does that too. According to the documentation:

If A is an m-by-n matrix with m ~= n and B is a column vector with m components, or a matrix with several such columns, then X = A\B is the solution in the least squares sense to the under- or overdetermined system of equations AX = B. In other words, X minimizes norm(A*X - B), the length of the vector AX - B. The rank k of A is determined from the QR decomposition with column pivoting (see Algorithm for details). The computed solution X has at most k nonzero elements per column. If k < n, this is usually not the same solution as x = pinv(A)*B, which returns a least squares solution.

So really, what you did in the first assignment was to solve the equation using LSE.

Does your assignment involve explicitly coding up a least-squares approximation, or just using another function available in MATLAB? If you can use another function, one option is LSQR:

x = lsqr(A,y);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!