大家好我有問題讓我的程序在GSL根目錄下工作。我正在嘗試找到解決方案。我正在尋找64行數據的解決方案,但在某些特定行中,程序無法繼續,可能是因爲沒有好的解決方案。但我希望程序在沒有找到解決方案時跳過線路。但我的程序有時會停止並出現以下消息: gsl:brent.c:74:錯誤:終結點不跨越y = 0 passou1passou2passou3默認調用GSL錯誤處理程序。 中止陷阱:6GSL中的錯誤 - 根目錄查找
所以,我做了一些打印以檢查正是我的程序停止,我發現,在gsl_root_fsolver_set(S,&樓x_lo,x_hi),但我怎麼沒發現打印這個值或者這個函數給我的東西。
我的程序在這裏,謝謝大家!
#include <stdio.h>
#include <math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_complex_math.h>
#include <gsl/gsl_roots.h>
#include "demo_fn.h"
#include "demo_fn.c"
int
main (void)
{
double NT, c;
c = 64.0/2.0;
char url[]="charm.txt";
double corr, core, a[64][3];
int nt, i = 0;
FILE *arq;
arq = fopen(url, "r");
if(arq == NULL)
printf("Erro, nao foi possivel abrir o arquivo\n");
else
while((fscanf(arq,"%lf %lf %i\n", &corr, &core, &nt))!=EOF) {
a[i][0]=corr;
a[i][1]=core;
a[i][2]=nt;
i++;
//printf("%lf, %lf, %i\n",corr, core, nt);
}
fclose(arq);
for (i= 0; i < 64; i++)
{
int status;
int iter = 0, max_iter = 200;
const gsl_root_fsolver_type *T;
gsl_root_fsolver *s;
double r = 0, r_expected = 4.0;
double x_lo = 0.0001, x_hi = 4.0;
double ratio1, ratio2;
ratio1 = a[i][0]/a[i+1][0];
ratio2 = a[i+1][0]/a[i+2][0];
printf ("ratio1: %lf, ratio2: %lf", ratio1, ratio2);
printf ("\n");
// if (ratio1*ratio2 > 0)
// {
printf("C(n_t) : %.15lf -- loop index : %i ----- ratio: %lf \n", a[i][0],i, ratio1);
gsl_function F;
struct quadratic_params params = {a[i][0], i, c, i+1, a[i+1][0]};
F.function = &quadratic;
printf ("passou1");
F.params = ¶ms;
T = gsl_root_fsolver_brent;
printf ("passou2");
//T = gsl_root_fsolver_bisection;
s = gsl_root_fsolver_alloc (T);
printf ("passou3");
gsl_root_fsolver_set (s, &F, x_lo, x_hi);
printf ("passou4");
printf ("using %s method\n", gsl_root_fsolver_name (s));
printf ("%5s [%9s, %9s] %9s %10s %9s\n", "iter", "lower", "upper", "root", "err", "err(est)");
do
{
iter++;
status = gsl_root_fsolver_iterate (s);
r = gsl_root_fsolver_root (s);
x_lo = gsl_root_fsolver_x_lower (s);
x_hi = gsl_root_fsolver_x_upper (s);
status = gsl_root_test_interval (x_lo, x_hi,0, 0.001);
if (status == GSL_SUCCESS)
{
printf ("Converged:\n");
}
printf ("%5d [%.7lf, %.7lf] %.7lf %+.7lf %.7lf\n", iter, x_lo, x_hi, r, r - r_expected, x_hi - x_lo);
}
while (status == GSL_CONTINUE && iter < max_iter);
gsl_root_fsolver_free (s);
// }
printf("\n");
}
return 0;
}
'#include「demo_fn.c」'是非常規的,至少可以說。 – EOF
這是因爲我正在寫這部分是我的功能,並演示演示.... – Gabriela