CPP   16

xbcuint

Guest on 20th July 2022 04:20:42 PM

  1. #include <iostream>
  2. #include <iomanip>
  3. #include "nr.h"
  4. using namespace std;
  5.  
  6. // Driver for routine bcuint
  7.  
  8. int main(void)
  9. {
  10.         const DP xx_d[4]={0.0,2.0,2.0,0.0};
  11.         const DP yy_d[4]={0.0,0.0,2.0,2.0};
  12.         int i;
  13.         DP ansy,ansy1,ansy2,ey,ey1,ey2;
  14.         DP x1,x1l,x1u,x1x2,x2,x2l,x2u,xxyy;
  15.         Vec_DP y(4),y1(4),y12(4),y2(4);
  16.         Vec_DP xx(xx_d,4),yy(yy_d,4);
  17.  
  18.         x1l=xx[0];
  19.         x1u=xx[1];
  20.         x2l=yy[0];
  21.         x2u=yy[3];
  22.         for (i=0;i<4;i++) {
  23.           xxyy=xx[i]*yy[i];
  24.           y[i]=xxyy*xxyy;
  25.           y1[i]=2.0*yy[i]*xxyy;
  26.           y2[i]=2.0*xx[i]*xxyy;
  27.           y12[i]=4.0*xxyy;
  28.         }
  29.         cout << endl << setw(6) << "x1" << setw(9) << "x2";
  30.         cout << setw(8) << "y" << setw(12) << "expect";
  31.         cout << setw(7) << "y1" << setw(11) << "expect";
  32.         cout << setw(7) << "y2" << setw(11) << "expect" << endl << endl;
  33.         cout << fixed << setprecision(4);
  34.         for (i=0;i<10;i++) {
  35.           x2=(x1=0.2*(i+1));
  36.           NR::bcuint(y,y1,y2,y12,x1l,x1u,x2l,x2u,x1,x2,ansy,ansy1,ansy2);
  37.           x1x2=x1*x2;
  38.           ey=x1x2*x1x2;
  39.           ey1=2.0*x2*x1x2;
  40.           ey2=2.0*x1*x1x2;
  41.           cout << setw(8) << x1 << setw(9) << x2 << setw(9) << ansy;
  42.           cout << setw(9) << ey << setw(9) << ansy1 << setw(9) << ey1;
  43.           cout << setw(9) << ansy2 << setw(9) << ey2 << endl;
  44.         }
  45.         return 0;
  46. }

Raw Paste


Login or Register to edit or fork this paste. It's free.