C ++中的简单曲线拟合实现(SVD最小二乘拟合或类似拟合) [英] Simple Curve Fitting Implimentation in C++ (SVD Least Sqares Fit or similar)

查看:358
本文介绍了C ++中的简单曲线拟合实现(SVD最小二乘拟合或类似拟合)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜寻互联网很长时间了,试图找到一种使用5个数据点来近似二阶多项式的简单,直观,快速的方法。

I have been scouring the internet for quite some time now, trying to find a simple, intuitive, and fast way to approximate a 2nd degree polynomial using 5 data points.

我正在使用VC ++ 2008。

I am using VC++ 2008.

我遇到了很多库,例如cminipack,cmpfit,lmfit等...,但它们似乎都不是很直观且我很难执行代码。

I have come across many libraries, such as cminipack, cmpfit, lmfit, etc... but none of them seem very intuitive and I have had a hard time implementing the code.

最终我将一组离散值放入一维数组中,我试图通过曲线拟合数据来找到虚拟最大点,然后找到该数据的最大点为非整数值(其中,整数值仅是查看数组时的最高精度)。

Ultimately I have a set of discrete values put in a 1D array, and I am trying to find the 'virtual max point' by curve fitting the data and then finding the max point of that data at a non-integer value (where an integer value would be the highest accuracy just looking at the array).

无论如何,如果有人做了某件事与此类似,并且可以指向我使用的软件包,也许是该软件包的简单实现,那就太好了!

Anyway, if someone has done something similar to this, and can point me to the package they used, and maybe a simple implementation of the package, that would be great!

我很乐意提供一些测试数据和图表向您显示我正在使用哪种类型的东西,但是我觉得我的要求非常简单。非常感谢。

I am happy to provide some test data and graphs to show you what kind of stuff I'm working with, but I feel my request is pretty straightforward. Thank you so much.

编辑:这是我编写的有效代码!
http://pastebin.com/tUvKmGPn

Here is the code I wrote which works! http://pastebin.com/tUvKmGPn

更改大小以更改使用的输入量

change size to change how many inputs are used

0 0
1 1
2 4
4 16
7 49

0 0 1 1 2 4 4 16 7 49

a:1 b:0 c:0
按任意键继续。 。 。

a: 1 b: 0 c: 0 Press any key to continue . . .

感谢您的帮助!

推荐答案

假设您要适合形式为

    y = ax^2 + bx + c 

到您的5个数据点,那么您所要做的就是求解一个3 x 3的矩阵方程。请看以下示例 http://www.personal.psu.edu /jhm/f90/lectures/lsq2.html -它可以解决您似乎正在描述的相同问题(仅使用更多数据点)。如果您对微积分有基本的了解,并且能够反转3x3矩阵(或者数值上更好的东西-我猜您是这样做的,因为您在问题标题中特别提到了SVD),那么此示例将阐明您需要做的事情。

to your 5 data points, then all you will need is to solve a 3 x 3 matrix equation. Take a look at this example http://www.personal.psu.edu/jhm/f90/lectures/lsq2.html - it works through the same problem you seem to be describing (only using more data points). If you have a basic grasp of calculus and are able to invert a 3x3 matrix (or something nicer numerically - which I am guessing you do given you refer specifically to SVD in your question title) then this example will clarify what you need to do.

这篇关于C ++中的简单曲线拟合实现(SVD最小二乘拟合或类似拟合)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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