• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            newplan

            阿基米德在洗澡時發(fā)現(xiàn)浮力原理,高興得來不及穿上褲子,跑到街上大喊:Eureka(我找到了)。
            posts - 39, comments - 26, trackbacks - 0, articles - 4
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            龍貝格Romberg算法cpp實現(xiàn)

            Posted on 2008-05-07 15:05 山泉彎延 閱讀(1489) 評論(1)  編輯 收藏 引用 所屬分類: 數(shù)值分析
            /*
            Romberg Algorithm 
            開發(fā)者:newplan
            開發(fā)日期:
            08.05.07 
            */


            /*=======================================*/
            /*INCLUDES*/ 
            #include           
            <cstdlib>
            #include           
            <iostream>
            #include           
            <cmath>
            /*=======================================*/
            /*MACROS  USED IN THIS FILE*/
            #define            MAX       
            20   
            #define            PRECISION 
            0.000008
            /*=======================================*/
            /*DECLARE NAMES IN STL NAMESAPCE */
            using  std::cout;
            using  std::endl;

            /*=======================================*/
            /*CLASS FUNC (FUNCTION OBJECT): THE ORIGINAL FUNCTION WE WANT TO INTEGRAL*/
            class  func{
                   
            public:
                          func(
            double x=1.0):exp(x){}
                          
            double operator()(const double& dnum)const{return pow(dnum,exp);}
                   
            private:
                          
            double exp;
                   };
            /*=======================================*/
            /*CLASS ECHELONFUNC (FUNCTION OBJECT)梯形法的遞推公式*/
            class  echelonFunc{
                   
            public:
                          echelonFunc(
            double begining,double ending,func & myfunc);
                          
            double operator()();
                   
            private:
                           
            double    h;
                           
            int       n;
                           
            double    T;
                           func      myfunc;
                           
            double    begining;
                           
            double    ending ;
                 };
            /*=======================================*/
            echelonFunc::echelonFunc(
            double begining,double ending,func & myfunc)
                          {
                           this
            ->begining=begining;
                           this
            ->ending=ending;
                           this
            ->h=ending-begining;
                           this
            ->n=0;
                           this
            ->T=0;
                           this
            ->myfunc=myfunc;//FUCNTION 
                          }
            /*------------------------------*/
            /* INCREASE FUNCTION 遞推函數(shù)*/
            double echelonFunc::operator()()
                          {   
            if(this->n==0)
                              {
                               this
            ->T=h*0.5*(myfunc(this->begining)+myfunc(this->ending));
                               this
            ->n=1;
                               return this
            ->T;
                              }
                              
            double len=0.5*h;
                              
            double sum=0;
                              
            int k=0;
                              
            for(k=0;k<this->n;k++)
                                  {
                                   sum
            +=myfunc(len);
                                   
            len=len+h;
                                  }
                              this
            ->T=0.5*this->T+0.5*h*sum;
                              this
            ->h/=2;
                              this
            ->n*=2;
                              return this
            ->T;
                          }
            /*=======================================*/
            /*THE MAIN CLASS IN THIS PROGRAM*/ 
            class  Romberg{
                   
            public:
                          Romberg(
            double begining,double ending,double exp);
                          ~Romberg();
                   
            private:
                          void RombergCPU();
            /*THE MOST IMPORTANT FUNCTION IN THIS PROGRAM*/
                          echelonFunc 
            *echol; 
                          
            double T[MAX][MAX];/*STO THE ROMBERG TABLE*/       
                   };
            /*------------------------------*/
            Romberg::Romberg(
            double begining ,double ending ,double paraexp)
            {
                func     myfunc(paraexp);
                echol 
            =  new echelonFunc(begining,ending,myfunc);
                RombergCPU();
            }
            /*------------------------------*/
            Romberg::~Romberg()
            {
                 delete echol;
            }
            /*------------------------------*/
            void Romberg::RombergCPU()
            {   clock_t Start; 
            //TIME STARAT
                clock_t 
            End;   //TIME END
                
            double *p[MAX];//WE USE THIS POINTER ARRAY TO ACCELERATE ALGOTITHM
                
            double **q;
                
            int i,j;
                Start 
            = clock();//TIME START FROM HERE
                
            for(i = 0,q = p; q < p+MAX; q++,i++)
                    
            *q= &T[i][0];
                
            double a,b,pows; 
                cout
            <<"-----------------------Romberg Algorithm---------------------"<<endl;
                
            *p[0]=(*echol)();
                cout
            <<"  "<<*p[0]<<endl;
                p[
            0]++;
                
            do{
                   
            *p[0]=(*echol)();
                    cout
            <<"  "<<*p[0];
                    p[
            0]++;
                    
            for(i=1;;i++)
                              {
                                pows
            =pow(4.0,double(i));
                                a
            =pows/(pows-1);
                                b
            =1/(pows-1);
                                
            *p[i]=a*(*(p[i-1]-1))-b*(*(p[i-1]-2));//ROMBERG ALGORITHM
                                cout
            <<"  "<<*p[i];
                                
            if(p[i]==&T[i][0])
                                  {
                                  p[i]
            ++
                                  break;
                                  } 
                                 p[i]
            ++;
                               }
                               cout
            <<endl;//fabs(T[i][0]-T[i-1][0])
                   }
            while(fabs(T[i][0]-T[i-1][0])>PRECISION);
                
                
            End = clock();//TIME END HERE
                
                cout
            <<"-------------------------------------------------------------"<<
                endl
            <<"  TIME SPEND:"<<(double)(End-Start)/CLOCKS_PER_SEC<<endl; 

            /*=======================================*/
            /*MAIN FUNCTION*/
            int main(int argc, char *argv[])
            {  
               Romberg  romberg(
            0,1,1.5);//ROMBERG API :BEGIN(0END(1EXP(1.5)
               system(
            "PAUSE");
               return EXIT_SUCCESS;
            }

            Feedback

            # re: 龍貝格Romberg算法cpp實現(xiàn)  回復(fù)  更多評論   

            2008-09-05 17:57 by matdu
            good
            亚洲精品乱码久久久久久蜜桃| 亚洲av成人无码久久精品| 欧美黑人激情性久久| 久久国产精品一区| 久久国产精品一区二区| 久久国产精品-国产精品| 91精品国产综合久久香蕉 | 久久无码国产| 青青草国产97免久久费观看| 人妻少妇精品久久| 久久综合狠狠综合久久综合88| 亚洲伊人久久大香线蕉综合图片| 久久狠狠爱亚洲综合影院 | 思思久久精品在热线热| 国内精品久久国产| 国产成人久久AV免费| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 久久综合成人网| 亚洲国产小视频精品久久久三级 | 久久伊人精品青青草原高清| 久久国产精品免费| 亚洲精品无码久久久久| 久久精品视频网| 久久影视综合亚洲| 久久国产精品成人片免费| 99国内精品久久久久久久| 亚洲精品国产第一综合99久久| 少妇高潮惨叫久久久久久| 色综合合久久天天综合绕视看| 日韩电影久久久被窝网| 国产精品久久影院| av色综合久久天堂av色综合在| 99久久精品国产毛片| 亚洲香蕉网久久综合影视 | 美女久久久久久| 国产高潮国产高潮久久久| 香蕉久久永久视频| 精品久久久久久国产免费了| 亚洲日韩中文无码久久| 欧美与黑人午夜性猛交久久久| www久久久天天com|