给定函数的Chebyshev逼近

您所在的位置:网站首页 切比雪夫准则拟合 给定函数的Chebyshev逼近

给定函数的Chebyshev逼近

2024-03-13 14:40| 来源: 网络整理| 查看: 265

//计算给定函数的Chebyshev逼近 #include #include #include #include

using namespace std;

const double pi = 3.141592653589793;

class chebyshev { private:  int div, i, j, n;  double a, b, func, F, sum, t0, t1, temp, x, y;  double *c, *f;

public:  chebyshev()  {   div = 10;  }  double function(double z)  {   func = sin(z) * z * z * (z * z - 2);   return func;  }  void cheb_coeff();  void cheb_eval();  ~chebyshev()  {   delete[] c, f;  } };

void main() {  chebyshev cheby;  cheby.cheb_coeff(); }

//计算逼近多项式的系数 void chebyshev::cheb_coeff() {  cout > n;  c = new double[n];  f = new double[n];  cout > a >> b;  for (i =  0; i < n; i++)  {   y = cos(pi * (i + 0.5) / n);   x = 0.5 * y * (b - a) + 0.5 * (b + a);   f[i] = function(x);  }  for (i = 0; i < n; i++)  {   sum = 0.0;   for (j = 0; j < n; j++)   {    sum += f[j] * cos(pi * i * (j + 0.5) / n);   }   c[i] = 2 * sum / n;   cout   y = (2 * x - a - b) / (b - a);   t0 = 1.0;   t1 = y;   F = c[1] * t1 + 0.5 * c[0];   for (j = 2; j < n; j++)   {    temp = t1;    t1 = 2 * y * t1 - t0;    t0 = temp;    F += c[j] * t1;   }   fout



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3