在哪里可以获得 Excel 式多项式回归曲线拟合的 Delphi/Pascal 实现?

发布于 2024-11-02 10:17:45 字数 72 浏览 0 评论 0原文

我有一组 XY 值(即散点图),并且我想要一个 Pascal 例程来生成适合这些点的 N 阶多项式的系数,就像 Excel 那样。

I have a set of X-Y values (i.e. a scatter plot) and I want a Pascal routine to generate the coefficients of a Nth order polynomial that fits those points, in the same way that Excel does.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

软糖 2024-11-09 10:17:45

我使用了 David J Taylor 的 Polyfit 示例 (curvefit.zip),它实现了最小二乘曲线拟合算法(也称为线性回归) David 的站点是 此处,但请继续阅读,因为我的版本更好。 (见下文)。

David 使用的算法源自一本针对 Pascal 程序员的科学数学书籍,Allen Miller 的曲线拟合例程来自《科学家和工程师的 Pascal 程序》一书,由 Juergen Loewner 于 1982 年 10 月键入并提交给 MTPUG,
并由 Jeff Weiss 针对 Turbo Pascal 进行了修正和改编。

您可以直接从 bitbucket 此处获取 curvefit.zip。 (您可以使用 Mercurial/TortoiseHG 克隆源代码,或从 bitbucket 下载 ZIP)

hg clone https://bitbucket.org/wpostma/curvefit curvefit

它可以在任何 Delphi 版本 5 及更高版本中运行,无论是否采用 Unicode,甚至包括 Delphi 10 Berlin。演示中有一个小图表,是我添加的。我还添加了一种强制结果通过原点的方法,这是一种常用技术,您希望对除常数项之外的所有值进行最佳拟合,常数项应该强制为零或某个实验得出的平均值。强制“空白扣除”设置为等于一系列分析“零样品”的平均值,在某些类型的分析化学中与某些类型的仪器一起使用时很常见,并且在其他科学案例中,它可以更多比最佳拟合有用,因为您可能希望最小化原点周围的误差,而不是最小化距离原点最远的曲线区域的误差。

我还应该澄清,出于线性回归的目的,“曲线”也可能是一条线,这就是我出于分析化学目的所需的情况,并且任何直线的方程 (y=mx+b) 也称为“校准曲线”。一阶曲线拟合是直线 (y = mx +b),二阶曲线拟合(如图所示)是抛物线 (y= nX^2 + mX + b)。正如您可能猜到的,该算法可以从一阶扩展到您希望的任何级别。不过我还没有测试过超过 8 个术语。

这是屏幕截图:

polyfit example with Chart

Bitbucket 项目链接:

https://bitbucket.org/wpostma/curvefit/overview

I used David J Taylor's Polyfit example (curvefit.zip), which implements a least squares curve fitting algorithm (also known as linear regression) David's site is here, but keep reading, because my version is better. (See below).

The origin of the algorithms David is using is a book on scientific math for Pascal programmers, Allen Miller's Curve Fitting routine from the book "Pascal Programs For Scientists And Engineers", typed and submitted to MTPUG in Oct. 1982 by Juergen Loewner,
and corrected and adaptated for Turbo Pascal by Jeff Weiss.

You can grab curvefit.zip directly from bitbucket here. (You can clone the sourcecode with Mercurial/TortoiseHG, or download a ZIP from bitbucket)

hg clone https://bitbucket.org/wpostma/curvefit curvefit

It runs in any delphi version 5 and up, Unicode or not, even Delphi 10 Berlin. It has a little chart in the demo, added by me. I also added a way to force the result through the origin, a common technique where you want a best fit on all values, other than the constant term, which should be forced, either to zero, or to some experimentally derived average. A forced "blank subtraction" which is set equal to the average of a series of analytical "zero samples", is common in certain types of analytical chemistry when used with certain types of instrumentation, and in other scientific cases, where it can be more useful than a best-fit, because you may wish to minimize error around the origin more than minimize error across the area of the curve that is farthest from the origin.

I should also clarify that for purposes of linear regression, a "curve" may also be a line, which is the case I needed for analytical chemistry purposes, and that equation for any straight line (y=mx+b) is also called the "calibration curve". A first order curve fit is a line (y = mx +b), a second order curve fit (shown in the picture) is a parabola (y= nX^2 + mX + b). As you might guess, this algorithm scales from first order up to any level you might wish. I haven't tested it above 8 terms though.

Here's a screenshot:

polyfit example with chart

Bitbucket project link:

https://bitbucket.org/wpostma/curvefit/overview

夜吻♂芭芘 2024-11-09 10:17:45

尝试 TPMath http://tpmath.sourceforge.net/ - 我多年来一直使用它来拟合希尔回归并可以推荐它。

Try TPMath http://tpmath.sourceforge.net/ - I've been using this for years for fitting a hill regression and can recommend it.

土豪我们做朋友吧 2024-11-09 10:17:45

查看Turbo Power的SysTools库中的函数,现已开源,包含StStat单元中的数学函数。

Check the functions in Turbo Power's SysTools library, now is open source, it includes math functions in the unit StStat.

栖竹 2024-11-09 10:17:45

尽管您已经给出了答案,但为了完整起见,我想我应该添加以下内容:

我们使用 SDL Components 的数学包,并且对此非常满意。

http://www.lohninger.com/delfcomp.html

经过深思熟虑,而且确实如此我们需要什么。

他的网站上还有各种其他有趣的工具。

Even though you've already awarded an answer, for completeness, I thought I'd add this:

We use SDL Components' Math pack and have been very happy with it.

http://www.lohninger.com/delfcomp.html

It's well thought out, and does exactly what we need.

He's got a variety of other interesting tools on his site.

舟遥客 2024-11-09 10:17:45

XlXtrFun 是我所知道和使用的最好的曲线拟合,但它适用于 Excel:

http://www.xlxtrfun.com/XlXtrFun/XlXtrFun.htm

XlXtrFun is the best curve fitting I know and use, but it is for Excel:

http://www.xlxtrfun.com/XlXtrFun/XlXtrFun.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文