9

問題の簡単な説明: 多項式のルート検索にニュートン ラフソン アルゴリズムを使用していますが、場合によっては機能しません。なぜ?

「C++ の数値レシピ」から、ニュートン ラフソン ハイブリッド アルゴリズムを採用しました。これは、ニューラフソンが適切に収束しない場合 (微分値が低い場合、または収束速度が速くない場合) に二等分します。

いくつかの多項式でアルゴリズムをチェックしたところ、うまくいきました。現在、所有しているソフトウェア内でテストを行っていますが、特定の多項式で常にエラーが発生します。私の問題は、他の多くの多項式がそうするのに、なぜこの多項式が結果に達しないのか分からないことです。多項式のアルゴリズムを改善したいので、どれが収束しない理由であるかを知る必要があるため、適切に処理できます。

次に、エラーのあるアルゴリズムと多項式について提供できるすべての情報を投稿します。

多項式:

f(t)= t^4 + 0,557257315256597*t^3 - 3,68254086033178*t^2 +
+ 0,139389107255627*t + 1,75823776590795

それは一次導関数です:

 f'(t)= 4*t^3 + 1.671771945769790*t^2 - 7.365081720663563*t + 0.139389107255627

プロット: ここに画像の説明を入力

ルーツ (Matlab による):

  -2.133112008595826          1.371976341295347          0.883715461977390 
  -0.679837109933505

アルゴリズム:

double rtsafe(double* coeffs, int degree, double x1, double x2,double xacc,double xacc2)
    {
    int j;
    double df,dx,dxold,f,fh,fl;
    double temp,xh,xl,rts;
    double* dcoeffs=dvector(0,degree);
    for(int i=0;i<=degree;i++)
        dcoeffs[i]=0.0;
    PolyDeriv(coeffs,dcoeffs,degree);
    evalPoly(x1,coeffs,degree,&fl);
    evalPoly(x2,coeffs,degree,&fh);
    evalPoly(x2,dcoeffs,degree-1,&df);
if ((fl > 0.0 && fh > 0.0) || (fl < 0.0 && fh < 0.0))
    nrerror("Root must be bracketed in rtsafe");

if (fl == 0.0) return x1;
if (fh == 0.0) return x2;

if (fl < 0.0) { // Orient the search so that f(xl) < 0.
    xl=x1;
    xh=x2;
} else {
    xh=x1;
    xl=x2;
}
rts=0.5*(x1+x2);    //Initialize the guess for root,
dxold=fabs(x2-x1);  //the "stepsize before last,"
dx=dxold;           //and the last step

evalPoly(rts,coeffs,degree,&f);
evalPoly(rts,dcoeffs,degree-1,&dx);

for (j=1;j<=MAXIT;j++) { //Loop over allowed iterations

    if ((((rts-xh)*df-f)*((rts-xl)*df-f) > 0.0) //Bisect if Newton out of range,
            || (fabs(2.0*f) > fabs(dxold*df))) { //or not decreasing fast enough.
        dxold=dx;
        dx=0.5*(xh-xl);
        rts=xl+dx;
        if (xl == rts) 
            return rts; //Change in root is negligible.
    } else {// Newton step acceptable. Take it.
        dxold=dx;
        dx=f/df;
        temp=rts;
        rts -= dx;
        if (temp == rts)
            return rts;
    }
    if (fabs(dx) < xacc) 
        return rts;// Convergence criterion
    evalPoly(rts,coeffs,degree,&f);
    evalPoly(rts,dcoeffs,degree-1,&dx);
    //The one new function evaluation per iteration.
    if (f < 0.0) //Maintain the bracket on the root.
        xl=rts;
    else
        xh=rts;

}
//As the Accuracy asked to the algorithm is really high (but usually easily reached)
//the results precission is checked again, but with a less exigent result
dx=f/df;
if(fabs(dx)<xacc2)
    return rts;
nrerror("Maximum number of iterations exceeded in rtsafe");
return 0.0;// Never get here.
}

アルゴリズムは、次の変数で呼び出されます。

x1=0.019
x2=1.05
xacc=1e-10
xacc2=0.1
degree=4
MAXIT=1000
coeffs[0]=1.75823776590795;
coeffs[1]=0.139389107255627;
coeffs[2]=-3.68254086033178;
coeffs[3]=0.557257315256597;
coeffs[4]=1.0;

問題は、アルゴリズムが最大反復回数を超え、 aproximumly のルートにエラーがあることです0.15

したがって、私の直接的で省略された質問は次のとおりです。多くの(少なくとも1000)他の非常に類似した多項式が正確なエラーに達しないのはなぜですか(1e-10の精度と少数の反復で!)

質問が難しく、直接的な答えがないことは承知していますが、数日間この問題に悩まされており、解決方法がわかりません。私の質問を読んでくれてありがとう。

4

2 に答える 2

3

コードを実行せずに、私の最初の推測では、解が収束したかどうかを判断するために、浮動小数点値と比較して等しいかどうかを判断しています。

   if (xl == rts) 
        return rts; //Change in root is negligible.

おそらく、比率として計算する必要があります。

   diff = fabs(xl - rts);
   if (diff/xl <= 1.0e-8)  // pick your own accuracy value here
      return rts;
于 2012-11-13T15:28:19.310 に答える
3

正確な理由はわかりませんが、この場合、関数が十分に速く減少しているかどうかを確認するチェックが機能していないようです。

次のようにするとうまくいきます:

  double old_f = f;

  .
  .
  .

    if ((((rts-xh)*df-f)*((rts-xl)*df-f) > 0.0) //Bisect if Newton out of range,
        || (fabs(2.0*f) > old_f)) { //or not decreasing fast enough.
  .
  .
  .

    if (fabs(dx) < xacc)
      return rts;// Convergence criterion
    old_f = f;

アップデート

コードに問題があるようです:

evalPoly(rts,dcoeffs,degree-1,&dx);

する必要があります

evalPoly(rts,dcoeffs,degree-1,&df);
于 2012-11-13T16:23:33.160 に答える