xdfridr.cpp

来自「C++数值算法原书代码」· C++ 代码 · 共 32 行

CPP
32
字号
#include <iostream>
#include <iomanip>
#include <cmath>
#include "nr.h"
using namespace std;

// Driver for routine dfridr

DP func(const DP x)
{
        return tan(x);
}

int main(void)
{
        DP x,h,dx,err;

        cout << "input x, h (h=0.0 to stop):" << endl;
        cout << fixed << setprecision(6);
        cin >> x >> h;
        while (h > 0.0) {
          dx=NR::dfridr(func,x,h,err);
          cout << setw(11) << "dfridr" << setw(12) << "actual";
          cout << setw(12) << "error" << endl;
          cout << setw(12) << dx << setw(12) << 1.0/SQR(cos(x));
          cout << setw(12) << err << endl << endl;
          cout << "input x, h (h=0.0 to stop):" << endl;
          cin >> x >> h;
        }
        return 0;
}

⌨️ 快捷键说明

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