double BEF(double p, double t)
{
	double g;
	int n, N=10;
	double r[N], sum_accel, err, sum = 0.0;
	double np1;

	
	if(t < 1.0)
	{
		g = gsl_sf_zeta(p);
		printf("error!\n");
	}
	else if(t > 1.0)
	{
//		exp(mu(t)/t)^n/n^(p)need mu function
		gsl_sum_levin_u_workspace * w = gsl_sum_levin_u_alloc(N);
		for (n = 0; n < N; n++)
		{
			np1 = n + 1.0;
			r[n] = pow(exp( mu(t)/t ) ,np1) / pow(np1, p);
			sum += r[n];
		}		
		gsl_sum_levin_u_accel(r, N, w, &sum_accel, &err);
		g = sum_accel;
		gsl_sum_levin_u_free(w);
	}
	
	return g;
}
Example #2
0
static VALUE rb_gsl_sum_levin_u_new(VALUE klass, VALUE nn)
{
  gsl_sum_levin_u_workspace *w = NULL;
  CHECK_FIXNUM(nn);
  w = gsl_sum_levin_u_alloc(FIX2INT(nn));
  return Data_Wrap_Struct(klass, 0, gsl_sum_levin_u_free, w);
}
Example #3
0
static VALUE rb_gsl_sum_accel(VALUE obj)
{
  gsl_sum_levin_u_workspace *w = NULL;
  double sum, err, sum_plain, *ptr;
  size_t terms_used, n, stride;  
  ptr = get_vector_ptr(obj, &stride, &n);
  w = gsl_sum_levin_u_alloc(n);
  gsl_sum_levin_u_accel(ptr, n, w, &sum, &err);
  sum_plain = w->sum_plain;
  terms_used = w->terms_used;
  gsl_sum_levin_u_free(w);
 return rb_ary_new3(4, rb_float_new(sum), rb_float_new(err), 
		    rb_float_new(sum_plain), INT2FIX(terms_used));
}
Example #4
0
File: test.c Project: lemahdi/mglib
void
check_full (double * t, double expected, const char * desc)
{
  double sum_accel, err_est, sd_actual, sd_est;
  
  gsl_sum_levin_u_workspace * w = gsl_sum_levin_u_alloc (N);

  gsl_sum_levin_u_accel (t, N, w, &sum_accel, &err_est);
  gsl_test_rel (sum_accel, expected, 1e-8, "full result, %s", desc);
  
  sd_est = -log10 (err_est/fabs(sum_accel) + GSL_DBL_EPSILON);
  sd_actual = -log10 (DBL_EPSILON + fabs ((sum_accel - expected)/expected));

  /* Allow one digit of slop */

  gsl_test (sd_est > sd_actual + 1.0, "full significant digits, %s (%g vs %g)", desc, sd_est, sd_actual);

  gsl_sum_levin_u_free (w);
}
//高温領域でのmuの温度依存性を調べる関数
double mu(double t)
{
	int j, N;
	double mu1, mu2, g2=-5.0, g, g_exact;
	int N2 = 10;
	double r[N2], sum_accel, err, sum = 0.0;
	int n;
	double np1;
	
	g_exact = gsl_sf_zeta(3.0/2.0)/pow(t, 3.0/2.0);
	
	//partition
	N = 1000;
	
	for(j=0; j<=6.5*N; j++)
	{
		mu1 = 0.0 - 1.0*j/N;

		gsl_sum_levin_u_workspace * w = gsl_sum_levin_u_alloc(N2);
		for (n = 0; n < N2; n++)
		{
			np1 = n + 1.0;
			r[n] = pow(exp( mu1/t ) ,np1) / pow(np1, 3.0/2.0);
			sum += r[n];
		}		
		gsl_sum_levin_u_accel(r, N2, w, &sum_accel, &err);
		g = sum_accel;
		gsl_sum_levin_u_free(w);
		if( fabs( g -  g_exact ) < fabs( g2 - g_exact ) )
		{
			//printf("%f %f %20.16f %20.16f %20.16f\n",t, mu1, g, g2, g_exact);
		}else
		{
			//printf("%f %f %20.16f %20.16f %20.16f\n",t, mu1, g, g2, g_exact);
			break;
		}
		g2 = g;
		mu2 = mu1;

	} 	
	return mu2;
}
Example #6
0
int
main (void)
{
  double t[N];
  double sum_accel, err;
  double sum = 0;
  int n;
  
  gsl_sum_levin_u_workspace * w 
    = gsl_sum_levin_u_alloc (N);

  const double zeta_2 = M_PI * M_PI / 6.0;
  
  /* terms for zeta(2) = \sum_{n=1}^{\infty} 1/n^2 */

  for (n = 0; n < N; n++)
    {
      double np1 = n + 1.0;
      t[n] = 1.0 / (np1 * np1);
      sum += t[n];
    }
  
  gsl_sum_levin_u_accel (t, N, w, &sum_accel, &err);

  printf ("term-by-term sum = % .16f using %d terms\n", 
          sum, N);

  printf ("term-by-term sum = % .16f using "F_ZU" terms\n", 
          w->sum_plain, w->terms_used);

  printf ("exact value      = % .16f\n", zeta_2);
  printf ("accelerated sum  = % .16f using "F_ZU" terms\n", 
          sum_accel, w->terms_used);

  printf ("estimated error  = % .16f\n", err);
  printf ("actual error     = % .16f\n", 
          sum_accel - zeta_2);

  gsl_sum_levin_u_free (w);
  return 0;
}
Example #7
0
void Hamaker_sommatoria(double* risultato) {
	// da: http://www.gnu.org/software/gsl/manual/html_node/Example-of-accelerating-a-series.html
	double epsilon_st, epsilon_me, epsilon_p, epsilon_h;
	int xi, xi_n;
	
	xi = (int) (2* M_PI * GSL_CONST_MKSA_BOLTZMANN * (in.T) / GSL_CONST_MKSA_PLANCKS_CONSTANT_HBAR);
	
	int numero_iterazioni = 100;
	double t[numero_iterazioni];
	double sum_accel, err;
	//double sum = 0;
	int n;
	
	gsl_sum_levin_u_workspace * w 
	 = gsl_sum_levin_u_alloc (numero_iterazioni);
	
	for (n = 0; n < numero_iterazioni; n++)
	 {
		 xi_n = xi * n;
		 // assumo le parentesi quadre della formula come parti intere
		
		epsilon_st = (74.8/(int)(1+xi_n/6.5E-5)) + (1.464/(int)(1+pow((xi_n/0.021), 2)))+ (0.737/(int)(1+pow((xi_n/0.067),2)))+ (0.153/(int) pow(1+(xi_n/0.092),2))+(0.014/(int)(1+pow((xi_n/0.2),2)))+(0.075/(int)(1+pow((xi_n/0.42),2)))+(0.078/(int)(1+pow((xi_n/12.7),2)))+ 1;
		
		
		epsilon_p = (1+(in.C1)/(int)(1+(xi_n/10)*(xi_n/10)));
		epsilon_h = (1+1/(int)(1+(xi_n/10.4)*(xi_n/10.4)));
		
		epsilon_me = (in.ni_p) * epsilon_p + (1-(in.ni_p)) * epsilon_h;
		
		t[n] = pow((epsilon_st-epsilon_me)/(epsilon_st+epsilon_me), 2);
	  }
	
	gsl_sum_levin_u_accel (t, numero_iterazioni, w, &sum_accel, &err);
	
	gsl_sum_levin_u_free (w);
	
	*risultato = sum_accel;
}