我想绘制一条曲线并生成一个与其紧密拟合的多项式。我该怎么办呢?
我有一条任意曲线(由一组点定义),我想生成一个将该曲线拟合到任意精度的多项式。解决这个问题的最佳方法是什么,或者是否已经有图书馆或在线服务可以执行此任务?
谢谢!
I have an arbitrary curve (defined by a set of points) and I would like to generate a polynomial that fits that curve to an arbitrary precision. What is the best way to tackle this problem, or is there already a library or online service that performs this task?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的“任意曲线”由一组点 (x_i,y_i) 描述,其中每个 x_i 都是唯一的,并且如果您的意思是“拟合”N 次最佳最小二乘多项式近似的计算,您可以简单地获得多项式的系数 b,
其中 X 是 x_i 值的向量,Y 是 Y_i 值的向量。这样你就可以增加N,直到获得你需要的精度。当然,您可以通过计算插值多项式来实现零近似误差。然而,数据拟合通常需要事先进行一些思考 - 您需要考虑您想要近似值实现的目标。有多种数学方法可以评估近似误差(通过使用不同的范数),其中的选择取决于您对所得近似值的要求。您可能会遇到许多潜在的陷阱(例如过度拟合),盲目地尝试拟合曲线可能会导致理论上合理但实际上对您毫无用处的近似值。如果上述方法不能满足您的要求,我建议对近似论进行一些研究,正如对您问题的评论中所建议的那样。
If your "arbitrary curve" is described by a set of points (x_i,y_i) where each x_i is unique, and if you mean by "fits" the calculation of the best least-squares polynomial approximation of degree N, you can simply obtain the coefficients b of the polynomial using
where X is the vector of x_i values, Y is the vector of Y_i values. In this way you can increase N until you obtain the accuracy you require. Of course you can achieve zero approximation error by calculating the interpolating polynomial. However, data fitting often requires some thought beforehand - you need to give thought to what you want the approximation to achieve. There are a variety of mathematical ways of assessing approximation error (by using different norms), the choice of which will depend on your requirements of the resulting approximation. There are also many potential pitfalls (such as overfitting) that you may come across and blindly attempting to fit curves may result in an approximation that is theoritically sound but utterly useless to you in practical terms. I would suggest doing a little research on approximation theory if the above method does not meet your requirements, as has been suggested in the comments on your question.