如何用用C线适合2D散射数据++ [英] How to fit the 2D scatter data with a line with C++

查看:144
本文介绍了如何用用C线适合2D散射数据++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MATLAB的工作,并为问题,我提出我可以用P = polyfit(X,Y​​,1)来估计最佳拟合线在平板散射数据。我想知道哪些资源,我可以靠实行符合C ++拟合算法。我知道有很多算法这一主题,对我来说我想到的算法应该是速度快,同时也能获得polyfit函数在MATLAB中具有相当的精度。

I used to work with MATLAB, and for the question I raised I can use p = polyfit(x,y,1) to estimate the best fit line for the scatter data in a plate. I was wondering which resources I can rely on to implement the line fitting algorithm with C++. I understand there are a lot of algorithms for this subject, and for me I expect the algorithm should be fast and meantime it can obtain the comparable accuracy of polyfit function in MATLAB.

推荐答案

我会建议从头开始对其进行编码。这是在C ++中一个非常简单的实现。您可以code起来既截距和梯度最小二乘(同样的方法 polyfit )的数据直接从这里公式

I would suggest coding it from scratch. It is a very simple implementation in C++. You can code up both the intercept and gradient for least-squares fit (the same method as polyfit) from your data directly from the formulas here

<一个href="http://en.wikipedia.org/wiki/Simple_linear_regression#Fitting_the_regression_line">http://en.wikipedia.org/wiki/Simple_linear_regression#Fitting_the_regression_line

这些都是封闭形式公式,使用循环,你可以很容易地评价自己。如果您使用更高程度的千篇一律,那么我建议一个矩阵库或更复杂的算法,但对于简单的线性回归你的描述上面,这是你所需要的。矩阵和线性代数程序将是矫枉过正这样的问题(在我看来)。

These are closed form formulas that you can easily evaluate yourself using loops. If you were using higher degree fits then I would suggest a matrix library or more sophisticated algorithms but for simple linear regression as you describe above this is all you need. Matrices and linear algebra routines would be overkill for such a problem (in my opinion).

这篇关于如何用用C线适合2D散射数据++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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