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

📄 xqtrap.cpp

📁 这是C++数值算法(第二版)的源代码,其中包含了目前一些比较常用的数值计算的算法.
💻 CPP
字号:
#include <iostream>
#include <iomanip>
#include <cmath>
#include "nr.h"
using namespace std;

// Driver for routine qtrap

// Test function
DP func(const DP x)
{
        return x*x*(x*x-2.0)*sin(x);
}

// Integral of test function
DP fint(const DP x)
{
        return 4.0*x*(x*x-7.0)*sin(x)-(pow(x,4.0)-14.0*x*x+28.0)*cos(x);
}

int main(void)
{
        const DP PIO2=1.570796326794896619;
        DP a=0.0,b=PIO2,s;

        cout << "Integral of func computed with QTRAP" << endl << endl;
        cout << fixed << setprecision(6);
        cout << "Actual value of integral is ";
        cout << setw(12) << (fint(b)-fint(a)) << endl;
        s=NR::qtrap(func,a,b);
        cout << "Result from routine QTRAP is " << setw(12) << s << endl;
        return 0;
}

⌨️ 快捷键说明

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