本文整理汇总了C++中Func::eval方法的典型用法代码示例。如果您正苦于以下问题:C++ Func::eval方法的具体用法?C++ Func::eval怎么用?C++ Func::eval使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Func
的用法示例。
在下文中一共展示了Func::eval方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: f
value_type
Stokhos::KL::OneDExponentialCovarianceFunction<value_type>::
bisection(const Func& func, const value_type& a, const value_type& b,
magnitude_type tol, int max_num_its)
{
value_type low, hi;
value_type fa = func.eval(a);
value_type fb = func.eval(b);
TEUCHOS_TEST_FOR_EXCEPTION(fa*fb > value_type(0.0), std::logic_error,
"Bounds [" << a << "," << b << "] must bracket the root!" << std::endl <<
"f(a) = " << fa << ", f(b) = " << fb << std::endl)
if (fa <= 0.0) {
low = a;
hi = b;
}
else {
low = b;
hi = a;
}
int nit = 0;
value_type u = low + (hi - low)/2.0;
value_type f = func.eval(u);
while ((Teuchos::ScalarTraits<value_type>::magnitude(hi - low) > 2.0*tol ||
Teuchos::ScalarTraits<value_type>::magnitude(f) > tol) &&
nit < max_num_its) {
//std::cout << "u = " << u << " f = " << f << std::endl;
if (f <= 0.0)
low = u;
else
hi = u;
u = low + (hi - low)/2.0;
f = func.eval(u);
++nit;
}
TEUCHOS_TEST_FOR_EXCEPTION(nit >= max_num_its, std::logic_error,
"Nonlinear solver did not converge!" << std::endl);
return u;
}
示例2: while
value_type
Stokhos::KL::OneDExponentialCovarianceFunction<value_type>::
newton(const Func& func, const value_type& a, const value_type& b,
magnitude_type tol, int max_num_its)
{
value_type u = (a+b)/2.0;
value_type f = func.eval(u);
int nit = 0;
while (Teuchos::ScalarTraits<value_type>::magnitude(f) > tol &&
nit < max_num_its) {
std::cout << "u = " << u << " f = " << f << std::endl;
value_type dfdu = func.deriv(u);
u -= f / dfdu;
f = func.eval(u);
++nit;
}
TEUCHOS_TEST_FOR_EXCEPTION(nit >= max_num_its, std::logic_error,
"Nonlinear solver did not converge!" << std::endl);
return u;
}