2

ベッセル関数の根を見つけるために正割法を実装しようとしています。私は最初に、gsl のストレート アップ ベッセル関数を使用するだけで問題を解決するコードをいくつか書きました。コードをいつ停止するかを評価できるように、エラーコードに変更しようとしています。このコードは、元の関数に対してうまく機能します。

    secant_method(gsl_sf_bessel_J0, bessel_function_roots[0], 0);

これで、次のように微分する関数を宣言します。

     double f (double x)
{
  return fnc (x);
}

エラーのあるベッセル関数を含めるように変更しようとすると

sectant_method(gsl_sf_bessel_J0_e, bessel_function_roots[0], 0);

それは動作を停止します。私が行った主な変更は次のとおりです。

double f (double x , gsl_sf_result *result)
{
    int fnc(x, result);
    return result->val;
}

だから私の関数は今読む

void secant_method(int fnc(double x , gsl_sf_result *result) , Root *bounds , int counter ){

//finding the derivative to start with
//setting up the derivative method for gsl library
double new_root, c;
double f (double x , gsl_sf_result *result)
{
   return result->val;
}
gsl_function F;
F.function = &f;
F.params = 0;
long double gradient;
double abserr,error;
gsl_sf_result *upper = malloc(sizeof(gsl_sf_result));
gsl_sf_result *lower = malloc(sizeof(gsl_sf_result));

fnc(bounds->upper_bound, upper);
fnc(bounds->lower_bound , lower);
printf ("x = %.16f -- %.16f\n" ,bounds->lower_bound , bounds->upper_bound);
printf ("f(x) = %g\n",lower->val);
printf ("f(x) = %g\n",upper->val);

gsl_deriv_central (&F, bounds->lower_bound, 1e-8, &gradient, &abserr);
printf ("f'(x) = %.10f +/- %.10f\n", gradient, abserr);

gsl_deriv_central を実装すると、セグメンテーション コア ダンプが返されます。問題は、私が作成したコードで関数を宣言する方法にあると思います。

誰かがこれについて私を助けることができれば、私は最も感謝しています:)

4

0 に答える 0