Esempio n. 1
0
static VALUE rb_gsl_fminimizer_set(VALUE obj, VALUE ff, VALUE xx, VALUE ss)
{
  gsl_multimin_fminimizer *gmf = NULL;
  gsl_multimin_function *F = NULL;
  gsl_vector *x = NULL, *s = NULL;
  CHECK_MULTIMIN_FUNCTION(ff);
  Data_Get_Struct(obj, gsl_multimin_fminimizer, gmf);
  Data_Get_Struct(ff, gsl_multimin_function, F);
  Data_Get_Vector(xx, x);
  Data_Get_Vector(ss, s);
  return INT2FIX(gsl_multimin_fminimizer_set(gmf, F, x, s));
}
Esempio n. 2
0
static VALUE rb_gsl_multimin_test_gradient(VALUE obj, VALUE gg, VALUE ea)
{
  gsl_vector *g = NULL;
  Need_Float(ea);
  Data_Get_Vector(gg, g);
  return INT2FIX(gsl_multimin_test_gradient(g, NUM2DBL(ea)));
}
Esempio n. 3
0
static VALUE rb_gsl_blas_daxpy(int argc, VALUE *argv, VALUE obj)
{
  double a;
  gsl_vector *x = NULL, *y = NULL;
  switch (TYPE(obj)) {
  case T_MODULE:
  case T_CLASS:
  case T_OBJECT:
    get_vector2(argc-1, argv+1, obj, &x, &y);
    Need_Float(argv[0]);
    //    a = RFLOAT(argv[0])->value;
    a = NUM2DBL(argv[0]);
    break;
  default:
    Data_Get_Struct(obj, gsl_vector, x);
    if (argc != 2) rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)",
			    argc);
    Need_Float(argv[0]);
    //    a = RFLOAT(argv[0])->value;
    a = NUM2DBL(argv[0]);
    Data_Get_Vector(argv[1], y);
    break;
  }
  gsl_blas_daxpy(a, x, y);
  return argv[argc-1];
}
Esempio n. 4
0
static int get_vector1(int argc, VALUE *argv, VALUE obj, gsl_vector **x)
{
  int flag = 0;
  switch (TYPE(obj)) {
  case T_MODULE:
  case T_CLASS:
  case T_OBJECT:
    if (argc != 1) rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)",
			    argc);
    Data_Get_Vector(argv[0], (*x));
    break;
  default:
    Data_Get_Vector(obj, (*x));
    flag = 1;
    break;
  }
  return flag;
}
Esempio n. 5
0
static VALUE rb_gsl_fdfminimizer_set(VALUE obj, VALUE ff, VALUE xx, VALUE ss, 
				     VALUE tt)
{
  gsl_multimin_fdfminimizer *gmf = NULL;
  gsl_multimin_function_fdf *F = NULL;
  gsl_vector *x;
  double stepsize, tol;
  int status;
  CHECK_MULTIMIN_FUNCTION_FDF(ff);
  Need_Float(ss); Need_Float(tt);
  Data_Get_Struct(obj, gsl_multimin_fdfminimizer, gmf);
  Data_Get_Struct(ff, gsl_multimin_function_fdf, F);
  Data_Get_Vector(xx, x);
  stepsize = NUM2DBL(ss);
  tol = NUM2DBL(tt);
  status = gsl_multimin_fdfminimizer_set(gmf, F, x, stepsize, tol);
  return INT2FIX(status);
}
Esempio n. 6
0
static VALUE rb_gsl_integration_qagp(int argc, VALUE *argv, VALUE obj)
{
  double epsabs, epsrel;
  double result, abserr;
  size_t limit;
  gsl_function *F = NULL;
  gsl_vector *v = NULL;
  gsl_integration_workspace *w = NULL;
  int status, intervals, flag = 0, flag2 = 0, itmp;
  switch (TYPE(obj)) {
  case T_MODULE:  case T_CLASS:  case T_OBJECT:
    CHECK_FUNCTION(argv[0]);
    Data_Get_Struct(argv[0], gsl_function, F);
    itmp = 1;
    break;
  default:
    Data_Get_Struct(obj, gsl_function, F);
    itmp = 0;
    break;
  }
  if (TYPE(argv[itmp]) == T_ARRAY) {
    v = make_cvector_from_rarray(argv[itmp]);
    flag2 = 1;
  } else {
    Data_Get_Vector(argv[itmp], v);
    flag2 = 0;
  }
  itmp += 1;
  flag = get_epsabs_epsrel_limit_workspace(argc, argv, itmp, &epsabs, &epsrel,
					   &limit, &w);

  status = gsl_integration_qagp(F, v->data, v->size, epsabs, epsrel, limit, w, 
				&result, &abserr);
  intervals = w->size;
  if (flag == 1) gsl_integration_workspace_free(w);
  if (flag2 == 1) gsl_vector_free(v);

  return rb_ary_new3(4, rb_float_new(result), rb_float_new(abserr), 
		     INT2FIX(intervals), INT2FIX(status));
}