Exemplo n.º 1
0
std::pair<std::vector<T>,std::vector<T> > FindRootsGSL(
	const TF &f,
	const T *guess,
	const gsl_multiroot_fdfsolver_type *solveType= gsl_multiroot_fdfsolver_hybridsj
){
	boost::shared_ptr<gsl_multiroot_fdfsolver> fsolve(
		gsl_multiroot_fdfsolver_alloc(solveType, f.arity()),
		gsl_multiroot_fdfsolver_free
	);
	if(fsolve==0)
		throw std::logic_error("Couldn't allocate GSL solver.");
	
	boost::shared_ptr<gsl_vector> gslGuess=detail::ToGSL(guess, guess+f.arity());

	detail::GSLFindRootsWrapper<TF> wrapper(f);
	
	gsl_multiroot_fdfsolver_set(fsolve.get(), &wrapper.m_fdf, gslGuess.get());
	
	while(true){
		int code=gsl_multiroot_fdfsolver_iterate(fsolve.get());
		if((code==GSL_ENOPROG) || (code==GSL_ENOPROGJ))
			break;
		if(code!=0)
			throw std::logic_error("Error while trying to find function roots using GSL.");
	}
	
	return std::make_pair(
		detail::FromGSL<T>(gsl_multiroot_fdfsolver_root(fsolve.get())),
		detail::FromGSL<T>(gsl_multiroot_fdfsolver_f(fsolve.get()))
	);
}
Exemplo n.º 2
0
CAMLprim value ml_gsl_multiroot_fdfsolver_root(value S, value r)
{
  CAMLparam2(S,r);
  gsl_vector *root;
  _DECLARE_VECTOR(r);
  _CONVERT_VECTOR(r);
  root=gsl_multiroot_fdfsolver_root(GSLMULTIROOTFDFSOLVER_VAL(S));
  gsl_vector_memcpy(&v_r, root);
  CAMLreturn(Val_unit);
}