d3r2.cpp

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

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

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

double fint(double x)
{
    //integral of func
	double aaa;
    aaa = 4.0 * x * (pow(x,2) - 7.0) * sin(x);
    return aaa - (pow(x , 4) - 14.0 * pow(x , 2) + 28.0) * cos(x);
}

void main()
{
    //program d3r2
    //driver for routine qtrap
    double pio2 = 1.5707963;
    double s, b,a = 0.0;
    b = pio2;
    cout<<endl;
    cout<<"integral of func computed with qtrap"<<endl;
    cout<<endl;
    cout<<"actual value of integral is:";
    cout<<(fint(b) - fint(a))<<endl;
    cout<<endl;
    qtrap(a, b, s);
    cout<<"result from routine qtrap is:";
    cout<<s<<endl;
}

⌨️ 快捷键说明

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