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

📄 xpoidev.cpp

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

// Driver for routine poidev

int main(void)
{
        const int N=20,NPTS=10000,ISCAL=200,LLEN=50;
        int i,j,klim,idum=(-13);
        Vec_INT dist(N+1);
        DP xm,dd;

        for (;;) {
          for (j=0;j<=N;j++) dist[j]=0;
          do {
            cout << "Mean of Poisson distribution (0.0<x<" << N << ".0) ";
            cout << "- Negative to end: " << endl;
            cin >> xm;
          } while (xm > N);
          if (xm < 0.0) break;
          for (i=0;i<NPTS;i++) {
            j=int(0.5+NR::poidev(xm,idum));
            if ((j >= 0) && (j <= N)) ++dist[j];
          }
          cout << fixed << setprecision(4);
          cout << "Poisson-distributed deviate, mean " << xm;
          cout << " of " << NPTS << " points" << endl;
          cout << setw(5) << "x" << setw(9) << "p(x)";
          cout << setw(11) << "graph:" << endl;
          for (j=0;j<=N;j++) {
            dd=DP(dist[j])/NPTS;
            klim=int(ISCAL*dd);
            if (klim > LLEN) klim=LLEN;
            string txt(klim,'*');
            cout << setw(6) << j << setw(9) << dd;
            cout << "  " << txt << endl;
          }
          cout << endl;
        }
        return 0;
}

⌨️ 快捷键说明

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