d5r5.cpp

来自「工程算法 这是一个很有用的工程数值算法集锦」· C++ 代码 · 共 45 行

CPP
45
字号
#include "iostream.h"
#include "math.h"

double func(double x)
{
    return (x * x) * (x * x - 2.0) * sin(x);
}

void main()
{
     //program d5r5
     //driver for routine chebev
     int nval = 40;
     double x,pio2 = 1.5707963;
     double a,b;
     double c[41];
     a = -pio2;
     b = pio2;
     chebft(a, b, c, nval);
     //test chebyshev evaluation routine
     cout<<endl;
     cout<<"How many terms in chebyshev evaluation?"<<endl;
     //input mval , between 6 and 40, mval=0 to end
     int mval = 20;
     cout<<mval<<endl;
     if ((mval <= 0) || (mval > nval))
	 {
		 return;
	 }
     cout<<"     x        Actual     Chebyshev fit"<<endl;
	 cout.setf(ios::fixed|ios::right);
	 cout.precision(6);
     for (int i = -8; i<=8; i++)
	 {
         x = i * pio2 / 10.0;
		 cout.width(13);
         cout<<x;
		 cout.width(13);
         cout<<func(x);
		 cout.width(13);
         cout<<chebev(a, b, c, mval, x)<<endl;
     }
}

⌨️ 快捷键说明

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