当前位置: 首页>>代码示例>>C++>>正文


C++ Polynomial::evaluate方法代码示例

本文整理汇总了C++中Polynomial::evaluate方法的典型用法代码示例。如果您正苦于以下问题:C++ Polynomial::evaluate方法的具体用法?C++ Polynomial::evaluate怎么用?C++ Polynomial::evaluate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Polynomial的用法示例。


在下文中一共展示了Polynomial::evaluate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: newtonRaphson

double Polynomial::newtonRaphson(double guess){
	Polynomial deriv = this->derivative();
	double nextGuess = guess;
	double fVal = this->evaluate(nextGuess);
	while(std::abs(fVal) > .000000001){
		if(0 == deriv.evaluate(nextGuess)){ nextGuess += 1; }
		nextGuess -= (fVal)/(deriv.evaluate(nextGuess));
		fVal = this->evaluate(nextGuess);
	}
	return nextGuess;
}
开发者ID:hegek87,项目名称:polynomial,代码行数:11,代码来源:polynomial.cpp

示例2: assert

    vector<CoeffT> Polynomial<CoeffT>::roots(size_t num_iterations, CoeffT ztol) const
    {
      assert(c.size() >= 1);
      size_t n = c.size() - 1;

      // initial guess
      vector<complex<CoeffT>> z0(n);
      for (size_t j = 0; j < n; j++) {
        z0[j] = pow(complex<double>(0.4, 0.9), j);
      }

      // durand-kerner-weierstrass iterations
      Polynomial<CoeffT> p = this->normalize();
      for (size_t k = 0; k < num_iterations; k++) {
        complex<CoeffT> num, den;
        for (size_t i = 0; i < n; i++) {
          num = p.evaluate(z0[i]);
          den = 1.0;
          for (size_t j = 0; j < n; j++) {
            if (j == i) { continue; }
            den = den * (z0[i] - z0[j]);
          }
          z0[i] = z0[i] - num / den;
        }
      }

      vector<CoeffT> roots(n);
      for (size_t j = 0; j < n; j++) {
        roots[j] = abs(z0[j]) < ztol ? 0.0 : real(z0[j]);
      }

      sort(roots.begin(), roots.end());
      return roots;
    }
开发者ID:Parallel-in-Time,项目名称:PFASST,代码行数:34,代码来源:polynomial_impl.hpp

示例3: findPolyIntervals

Intervals PolynomialIntervalSolver::findPolyIntervals(const Polynomial &poly)
{
    const double eps = 1e-8;
    
    int leadcoeff=0;
    std::vector<Interval> empty;
    std::vector<Interval> all;
    all. push_back(Interval(-std::numeric_limits<double>::infinity(),
                            std::numeric_limits<double>::infinity()));
    
    const std::vector<double> &coeffs = poly.getCoeffs();
    int deg = coeffs.size()-1;
    
    for(int i=0; i<(int)coeffs.size(); i++)
        assert(!isnan(coeffs[i]));
    
    // get rid of leading 0s
//    for(leadcoeff=0; leadcoeff < (int)coeffs.size() && fabs(coeffs[leadcoeff]) < eps; leadcoeff++)
//    {
//        deg--;
//    }
    
    // check for the zero polynomial
    if(deg < 0)
    {
        return Intervals(empty);
    }
    
    // check for constant polynomial
    if(deg == 0)
    {
        double val = poly.evaluate(0);
        if(val > 0)
        {
            return Intervals(all);
        }
        return Intervals(empty);
    }
    
    // nonconstant polynomial... rpoly time!!!
    assert(deg <= 6);
    double zeror[6];
    double zeroi[6];
    int numroots = rf.rpoly(&coeffs[leadcoeff], deg, zeror, zeroi);
    
    std::vector<double> roots;
    for(int i=0; i<numroots; i++)
        if( fabs(zeroi[i]) < eps )
            roots.push_back(zeror[i]);
    
    // no roots: check at 0
    if(roots.size() == 0)
    {
        double val = poly.evaluate(0);
        if(val > 0)
            return Intervals(all);
        return Intervals(empty);
    }
    
    std::sort(roots.begin(), roots.end());
    
    std::vector<Interval> intervals;
    
    for(int i=0; i<(int)roots.size(); i++)
    {
        if(i == 0)
        {
            //check poly on (-inf, r)
            
            double t = roots[i]-1;
            double val = poly.evaluate(t);
            if(val > 0)
            {
                intervals.push_back(Interval(-std::numeric_limits<double>::infinity(),
                                             roots[i]));
            }
        }
        if(i == (int)roots.size()-1)
        {
            //check poly on (r, inf)
            double t = roots[i]+1;
            double val = poly.evaluate(t);
            if(val > 0)
            {
                intervals.push_back(Interval(roots[i],
                                             std::numeric_limits<double>::infinity()));
            }
        }
        
        if(i < (int)roots.size()-1)
        {
            // check poly on (r, r+1)
            double t = 0.5*(roots[i]+roots[i+1]);
            double val = poly.evaluate(t);
            if(val > 0)
            {
                intervals.push_back(Interval(roots[i],
                                             roots[i+1]));
            }
        }
//.........这里部分代码省略.........
开发者ID:js4768,项目名称:4167T2M2,代码行数:101,代码来源:ContinuousTimeUtilities.cpp


注:本文中的Polynomial::evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。