⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 leastsq.h

📁 小波提升格式的源代码
💻 H
字号:

/**

  Least squares fit for four evenly spaced points on the y-axis.
  The x-axis values are, respectively, {0, 1, 2, 3}.  As with
  polynomial interpolation for four points at known x-axis
  locations degenerates into a set of linear coefficients.

  x0..x3 = {0, 1, 2, 3}.  So the mean of the x-axis points is
  Xm = 6/4 = 1.5.

  The sum of the squares around the mean for X is similarly
  constant since we know that Xi = {0, 1, 2, 3} for the
  four points.

     SSxx = sq(0 - 1.5) + sq(1 - 1.5) + sq(2 - 1.5) + sq(3 - 1.5)
     SSxx = sq(-1.5) + sq(-0.5) + sq(0.5) + sq(1.5)
     SSxx = 2.25 + 0.25 + 0.25 + 2.25
     SSxx = 5.0

  For the linear equation
  
     y = a + bx

     b = SSxy / SSxx

     Ym = mean of Yi

     SSxy = (-1.5)(y0 - Ym) + (-0.5)(y1 - Ym) + (0.5)(y2 - Ym) + (1.5)(y3 - Ym)

     SSxy = -3(y0 - Ym)/2 + -(y1 - Ym)/2 + (y2 - Ym)/2 + 3(y3 - Ym)/2

     SSxy = (-3y0 + 3Ym)/2 + (-y1 + Ym)/2 + (y2 - Ym)/2 + (3y3 - 3Ym)/2

     SSxy = (-3y0 + 3Ym + (-y1) + Ym + y2 - Ym + 3y3 - 3Ym)/2

     SSxy = (-3y0 - y1  + y2 + 3y3 )/2

     b = SSxy / SSxx = ((-3y0 - y1  + y2 + 3y3 )/2)/5

     b = SSxy / SSxx = (-3y0 - y1  + y2 + 3y3 )/10
 */

class leastsq {
 private:
   double a, b;

 public:
   leastsq( double y0, double y1, double y2, double y3 )
   {
      const double Xm = 1.5;
      double Ym = (y0 + y1 + y2 + y3)/4.0;
      b = ((-3 * y0) - y1 + y2 + (3 * y3))/10.0;
      a = Ym - (b * Xm);
   }

   double yPoint( double x )
   {
      double y = a + b * x;
      return y;
   }
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -