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


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

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


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

示例1: makeElement

FFElement FiniteField::makeElement(const Polynomial& p) const {
    assert(p.getMod() == getP());
    if (p.getDomain() == domain) return FFElement(p, this);
    std::vector<FieldElement> coeffs;
    for (auto& c : p.getCoeffs()) coeffs.push_back(domain->getField()->makeElement(c.getVal()));
    return FFElement(domain->makeElement(coeffs), this);
}
开发者ID:NivenT,项目名称:Cryptography,代码行数:7,代码来源:FiniteField.cpp

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