如何在MATLAB中使用最小二乘逼近? [英] How do I use the least squares approximation in MATLAB?

查看:67
本文介绍了如何在MATLAB中使用最小二乘逼近?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于线性代数中的作业分配,我已经使用MATLAB的\运算符(这是推荐的实现方式)解决了以下方程式:

For a homework assignment in linear algebra, I have solved the following equation using MATLAB's \ operator (which is the recommended way of doing it):


A = [0.2 0.25; 0.4 0.5; 0.4 0.25];
y = [0.9 1.7 1.2]';
x = A \ y

产生以下答案:


x =
1.7000
2.0800

对于下一部分作业,我应该使用最小二乘近似法求解相同的方程(然后将其与先前值进行比较,以了解近似度的准确性).

For the next part of assignment, I'm supposed to solve the same equation using the least squares approximation (and then compare it against the prior value to see how accurate the approximation is).

我如何找到在MATLAB中执行此操作的方法?

How can I find a way of doing that in MATLAB?

以前的工作:我发现了函数lsqlin,该函数似乎能够解决上述类型的方程,但是我不知道提供哪个参数或以什么顺序提供.

Prior work: I have found the function lsqlin, which seems to be able to solve equations of the above type, but I don't understand which arguments to supply it nor in what order.

推荐答案

mldivide ,(" \ ")实际上也可以做到这一点.根据文档:

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

如果A是m〜= n的m×n矩阵并且B是具有m个分量的列向量或具有多个此类列的矩阵,则X = A \ B是最小二乘意义上的解到方程AX = B的欠定或超定系统.换句话说,X使范数(A * X-B)最小化向量AX-B的长度.A的秩k由带有列的QR分解确定旋转(有关详细信息,请参见算法).计算出的解X每列最多具有k个非零元素.如果k < n,这通常不同于x = pinv(A)* B,后者返回最小二乘解.

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.

实际上,您在第一份作业中所做的就是使用LSE求解方程.

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

这篇关于如何在MATLAB中使用最小二乘逼近?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆