的n个点逼近与最佳拟合曲线 [英] Approximation of n points to the curve with the best fit

查看:465
本文介绍了的n个点逼近与最佳拟合曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有n个点(2D)的列表:P1(X0,Y0),P2(X1,Y1),P3(X2,Y2)... 点满足每一个点都有独特的坐标,也是每个点xi的坐标,易建联> 0和喜,易建联都是整数的情况。

I have a list of n points(2D): P1(x0,y0), P2(x1,y1), P3(x2,y2) … Points satisfy the condition that each point has unique coordinates and also the coordinates of each point xi, yi> 0 and xi,yi are integers.

的任务是写一个算法,这使得这些点的逼近

The task is to write an algorithm which make approximation of these points

  • 要曲线 Y = | ACOS(Bx的)| 用最合适的(接近或等于100%)
  • 和使系数A和B是越简单越好。
  • to the curve y = | Acos (Bx) | with the best fit (close or equal to 100%)
  • and so that the coefficients A and B were as simple as possible.

我想编写一个程序,在C#中,但最大的问题,我是要找到一个合适的算法。有没有人将能够帮助我?

I would like to write a program in C # but the biggest problem for me is to find a suitable algorithm. Has anyone would be able to help me with this?

推荐答案

根据增加的超越方程求解精度我想尝试在C ++:

Based on Increasing accuracy of solution of transcendental equation I would try this in C++:

// (global) input data
#define _n 100
double px[_n]; // x input points
double py[_n]; // y input points

// approximation
int ix;
double e;
approx aa,ab;
//            min  max   step  recursions  ErrorOfSolutionVariable
for (aa.init(-100,+100.0,10.00,3,&e);!aa.done;aa.step())
for (ab.init(-0.1,+  0.1, 0.01,3,&e);!ab.done;ab.step())
    {
    for (e=0.0,ix=0;ix<_n;ix++) // test all measured points (e is cumulative error)
        {
        e+=fabs(fabs(aa.a*cos(ab.a*px[ix]))-py[ix]);
        }
    }
// here aa.a,ab.a holds the result A,B coefficients

它使用我的类从上述

  • 您需要设置最小值,最大值的范围,以配合您的数据集
  • 可以通过增加递归数增加精度
  • 可以根据需要通过提高性能
    • 在使用并不是所有的点不准确的递归层
    • 在提高起动步骤(但过大的话,就可以无效的结果)
    • you need to set the min,max and step ranges to match your datasets
    • can increase accuracy by increasing the recursions number
    • can improve performance if needed by
      • using not all points for less accurate recursion layers
      • increasing starting step (but if too big then it can invalidate result)

      您应该还添加输入点的情节和输出曲线,看看你接近的解决方案。如果没有有关输入点的详细信息,很难更具体。您可以更改差额计算电子来匹配任何需要的方式,这是ABS的区别只是总和(可以用最小二乘法或什么都...)

      You should also add a plot of your input points and the output curve to see if you are close to solution. Without more info about the input points it is hard to be more specific. You can change the difference computation e to match any needed approach this is just sum of abs differences (can use least squares or what ever ...)

      这篇关于的n个点逼近与最佳拟合曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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