• <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>

            牽著老婆滿街逛

            嚴以律己,寬以待人. 三思而后行.
            GMail/GTalk: yanglinbo#google.com;
            MSN/Email: tx7do#yahoo.com.cn;
            QQ: 3 0 3 3 9 6 9 2 0 .

            Blitz++ 計算二階導數

            // 整理?by?RobinKin

            #include?
            < blitz / vector.h >

            using ? namespace ?blitz;

            int ?main()
            {
            ????
            // ?In?this?example,?the?function?cos(x)^2?and?its?second?derivative
            ????
            // ?2?(sin(x)^2?-?cos(x)^2)?are?sampled?over?the?range?[0,1).
            ????
            // ?The?second?derivative?is?approximated?numerically?using?a
            ????
            // ?[?1?-2??1?]?mask,?and?the?approximation?error?is?computed.

            /* ?cos(x)^2??的二階導數?是2?(sin(x)^2?-?cos(x)^2)

            下面在[0,1)?的范圍中,以delta為步長?,用[?1?-2??1?]?的方法計算二階導數

            看看和精確值的誤差
            */



            ????
            const ? int ?numSamples? = ? 100 ;?????????????? // ?Number?of?samples
            ???? double ?delta? = ? 1 .? / ?numSamples;?????????? // ?Spacing?of?samples
            ????Range?R( 0 ,?numSamples? - ? 1 );?????????????? // ?Index?set?of?the?vector

            ????
            // ?Sample?the?function?y?=?cos(x)^2?over?[0,1)
            ????
            //
            ????
            // ?An?object?of?type?Range?can?be?treated?as?a?vector,?and?used
            ????
            // ?as?a?term?in?vector?expressions.
            ????
            //
            ????
            // ?The?initialization?for?y?(below)?will?be?translated?via?expression
            ????
            // ?templates?into?something?of?the?flavour
            ????
            //
            ????
            // ?for?(unsigned?i=0;?i?<?99;?++i)
            ????
            // ?{
            ????
            // ?????double?_t1?=?cos(i?*?delta);
            ????
            // ?????y[i]?=?_t1?*?_t1;
            ????
            // ?}
            ????
            ????Vector
            < double > ?y? = ?sqr(cos(R? * ?delta));

            ????
            // ?Sample?the?exact?second?derivative
            ????Vector < double > ?y2exact? = ? 2.0 ? * ?(sqr(sin(R? * ?delta))? - ?sqr(cos(R? * ?delta)));

            ????
            // ?Approximate?the?2nd?derivative?using?a?[?1?-2??1?]?mask
            ????
            // ?We?can?only?apply?this?mask?to?the?elements?1?..?98,?since
            ????
            // ?we?need?one?element?on?either?side?to?apply?the?mask.
            ????Range?I( 1 ,numSamples - 2 );
            ????Vector
            < double > ?y2(numSamples);

            ????y2(I)?
            = ?(y(I - 1 )? - ? 2 ? * ?y(I)? + ?y(I + 1 ))? / ?(delta * delta);
            ??
            ????
            // ?The?above?difference?equation?will?be?transformed?into
            ????
            // ?something?along?the?lines?of
            ????
            //
            ????
            // ?double?_t2?=?delta*delta;
            ????
            // ?for?(int?i=1;?i?<?99;?++i)
            ????
            // ?????y2[i]?=?(y[i-1]?-?2?*?y[i]?+?y[i+1])?/?_t2;
            ?
            ????
            // ?Now?calculate?the?root?mean?square?approximation?error:

            ????
            double ?error? = ?sqrt(mean(sqr(y2(I)? - ?y2exact(I))));
            ?
            ????
            // ?Display?a?few?elements?from?the?vectors.
            ????
            // ?This?range?constructor?means?elements?1?to?91?in?increments
            ????
            // ?of?15.
            ????Range?displayRange( 1 ,? 91 ,? 15 );
            ?
            ????cout?
            << ? " Exact?derivative: " ? << ?y2exact(displayRange)? << ?endl
            ?????????
            << ? " Approximation:??? " ? << ?y2(Range(displayRange))? << ?endl
            ?????????
            << ? " RMS?Error:??????? " ? << ?error? << ?endl;

            ????
            return ? 0 ;
            }



            Output:

            Exact?derivative:[????
            - 1.9996 ?? - 1.89847 ?? - 1.62776 ?? - 1.21164 ? - 0.687291 ? - 0.1015495
            ???]
            Approximation:???[???
            - 1.99953 ?? - 1.89841 ??? - 1.6277 ??? - 1.2116 ? - 0.687269 ? - 0.1015468
            ???]
            RMS?Error:???????
            4.24826e-05

            posted on 2006-07-01 13:23 楊粼波 閱讀(699) 評論(0)  編輯 收藏 引用

            久久综合久久综合亚洲| 欧美伊香蕉久久综合类网站| 久久狠狠爱亚洲综合影院| 久久精品亚洲一区二区三区浴池| 久久久精品人妻一区二区三区四| 99久久无码一区人妻| 国内精品久久久久影院薰衣草 | 国产91色综合久久免费| 亚洲伊人久久大香线蕉苏妲己| 久久久久久午夜精品| 国产精品一久久香蕉国产线看 | 国产成人久久精品区一区二区| 亚洲国产成人久久一区久久| 国产精品一区二区久久不卡| 久久精品视频一| 女同久久| 久久久久亚洲AV无码去区首| 人妻无码久久一区二区三区免费 | 香蕉久久av一区二区三区| 久久精品国产只有精品66| 精品久久久久久无码专区| 亚洲欧洲久久av| 日韩亚洲国产综合久久久| 国产一区二区精品久久凹凸| 99久久精品国产麻豆| 九九久久自然熟的香蕉图片| 99久久无色码中文字幕人妻| 久久人人添人人爽添人人片牛牛| 欧美粉嫩小泬久久久久久久| 久久精品成人欧美大片| 国产精品久久久99| 精品久久久久一区二区三区| 国产精品美女久久久网AV| 久久国产精品99精品国产987| 久久精品国产亚洲一区二区| 国产精品视频久久| 国产精品九九久久免费视频 | 国产亚洲精午夜久久久久久| 久久久久国产一区二区三区| 久久久久综合中文字幕| 久久亚洲精品国产亚洲老地址|