给定函数的Chebyshev逼近
来源:互联网 发布:淘宝联盟2016 编辑:程序博客网 时间:2024/06/11 09:54
//计算给定函数的Chebyshev逼近
#include <iostream>
#include <math.h>
#include <fstream>
#include <iomanip>
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输入n:";
cin >> n;
c = new double[n];
f = new double[n];
cout << "\n输入区间下限和上限(即a和b)";
cin >> 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 << "\nc[" << i << "] = " << c[i] << endl;
}
cheb_eval();
}
void chebyshev::cheb_eval()
{
ofstream fout("chebyshev.txt");
x = a;
for (i = 0; i <= div; i++)
{
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 << x << setw(15) << F << endl;
x += (b - a) / div;
}
fout.close();
}
- 给定函数的Chebyshev逼近
- 有理逼近的误差函数
- Chebyshev的文字直观解释
- BP神经网络的函数逼近功能
- 用BP网络完成函数的逼近
- 函数逼近与插值的区别
- keras实现简单的函数拟合逼近
- 二分函数逼近法
- 函数逼近问题
- 函数逼近与曲线拟合
- 函数逼近方法
- 算法_14:函数逼近
- 数值分析 函数逼近
- ReLU深度网络能逼近任意函数的原因
- ReLU深度网络能逼近任意函数的原因
- matlab 泰勒函数逼近实验
- Chebyshev 展开
- 三角函数逼近锯齿函数和阶梯函数
- JAVA学习笔记----接口与内部类
- 下标方式引起的crash的原因
- 第2章 变量和基本类型
- mysql 千万级的 count统计对比
- 免费的企业级正版Windows安全管理利器——System Center 2012 Endpoint Protection
- 给定函数的Chebyshev逼近
- 精确表达浮点数
- QueryPerformanceFrequency
- Linux网络设置3——ssh工具使用的注意点
- HDU上一道最小生成树模板题的练习
- 怀念—伤心者,不痛不痒,冷暖自知
- 顺序线性表
- 顺序线性表2
- 链式线性表