如何在 MATLAB 中使用最小二乘近似?
对于线性代数的家庭作业,我使用 MATLAB 的 \
运算符(这是推荐的方法)求解了以下方程:
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
对于作业的下一部分,我我应该使用最小二乘近似来求解相同的方程(然后将其与先前的值进行比较,看看近似值有多准确)。
我怎样才能在 MATLAB 中找到实现这一点的方法?
之前的工作:我找到了函数lsqlin
,它似乎能够求解上述类型的方程,但我不明白要提供哪些参数,也不知道以什么顺序提供。
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
which produces the following answer:
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).
How can I find a way of doing that in MATLAB?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
mldivide, ("\") 实际上也是这样做的。根据文档:
事实上,你在第一个作业中所做的就是使用 LSE 求解方程。
mldivide, ("\") actually does that too. According to the documentation:
So really, what you did in the first assignment was to solve the equation using LSE.
您的作业是否涉及显式编码最小二乘近似,或者仅使用 MATLAB 中提供的其他函数?如果您可以使用其他函数,一个选项是 LSQR:
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: