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


C++ polynomial类代码示例

本文整理汇总了C++中polynomial的典型用法代码示例。如果您正苦于以下问题:C++ polynomial类的具体用法?C++ polynomial怎么用?C++ polynomial使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: div_monomial

	static polynomial div_monomial(const polynomial& divident,
			const polynomial& divisor) {
		int_type degree = divident.degree() - divisor.degree();
		int_type coefficient = divident.data.begin()->second
				/ divisor.data.begin()->second;
		return { {degree, coefficient}};
	}
开发者ID:xackus,项目名称:kolocpp,代码行数:7,代码来源:polynomial.hpp

示例2: while

polynomial operator *(const polynomial &p1, const polynomial &p2)
{
    polynomial p3;
    Iterator<polyterm> poly1, poly2;
    Node<polyterm> newTerm;


    poly1=p1.Begin();
    while(poly1.GetNode()!=NULL)
    {

        poly2 = p2.Begin();
        while(poly2.GetNode()!=NULL)
        {
            newTerm = *poly1.GetNode()* *poly2.GetNode();

            p3.InsertSorted(new Node<polyterm>(newTerm));


            poly2.Next();
        }
        poly1.Next();
    }
    return p3;




}
开发者ID:jonathanpchan,项目名称:SchoolWork,代码行数:29,代码来源:polynomial.cpp

示例3: derivative

 friend polynomial derivative(polynomial const& p) {
  int s = p.size();
  if(s == 0) return {};

  polynomial res;
  res.coeffs.resize(s-1);
  for(int n = 0; n < s-1; ++n)
   res.coeffs(n) = p.coeffs(n+1) * CoeffType(n+1);
  return res;
 }
开发者ID:krivenko,项目名称:som,代码行数:10,代码来源:polynomial.hpp

示例4: size

 polynomial operator+(const polynomial<T>& o) const
 {
   int len;
   const polynomial<T> *p;
   size() >= o.size() ? (p=this, len=size()) : (p=&o, len=o.size());
   polynomial<T> out(len);
   std::transform(vals->data(),vals->data()+std::min(size(),o.size()),o.vals->data(),out.vals->data(),[](T a, T b){return a+b;});
   if (size() != o.size()) std::copy_n(&p->element(std::min(size(),o.size())),abs(size()-o.size()),&out(std::min(size(),o.size())));
   return out;
 }
开发者ID:andyras,项目名称:SplitOp,代码行数:10,代码来源:polynomial.hpp

示例5: result

    const polynomial operator+ (polynomial operand) const {
        std::vector<double> result (std::max(degree(), operand.degree()) + 1);

        for (int i = 0; i < result.size(); i++) {
            double x = i <= degree() ? coefficients[i] : 0.0;
            double y = i <= operand.degree() ? operand[i] : 0.0;
            result[i] = x + y;
        }

        return polynomial { result };
    }
开发者ID:harrishancock,项目名称:nummeth,代码行数:11,代码来源:polynomial.hpp

示例6: antiderivative

 friend polynomial antiderivative(polynomial const& p) {
  int s = p.size();
  if(s == 0) return {};

  polynomial res;
  res.coeffs.resize(s+1);
  res.coeffs(0) = CoeffType{};
  for(int n = 1; n < s+1; ++n)
   res.coeffs(n) = p.coeffs(n-1) / CoeffType(n);
  return res;
 }
开发者ID:krivenko,项目名称:som,代码行数:11,代码来源:polynomial.hpp

示例7: printpoly

void printpoly(ostream &dst, const polynomial<num,Nvar,Ndeg> &p)
{
    int exps[Nvar] = {0};
    for (int i=0; i<p.size; i++)
    {
        p.exponents(i,exps);
        for (int j=0; j<Nvar; j++)
            cout << exps[j] << " ";
        cout << " " << p[i] << endl;
        assert(i == p.term_index(exps));
    }
}
开发者ID:loriab,项目名称:pcmsolver,代码行数:12,代码来源:unittest_taylor.cpp

示例8: sturm_chain

std::vector<polynomial> sturm_chain (polynomial p) {
    std::vector<polynomial> chain (p.degree() + 1);

    chain[0] = p;
    chain[1] = p.derivative();

    for (int i = 2; i < chain.size(); i++) {
        chain[i] = -(chain[i-2] % chain[i-1]);
    }

    return chain;
}
开发者ID:harrishancock,项目名称:nummeth,代码行数:12,代码来源:polynomial.hpp

示例9: test_np

void test_np(const polynomial& test)
{
    unsigned int exponent;

    cout << "Enter exponent: ";
    cin >> exponent;

    cout << "For polynomial: ";
    view(test);
    cout << "next_term(" << exponent << ") = "
	 << test.next_term(exponent) << endl;
    cout << "previous_term(" << exponent << ") = "
	 << test.previous_term(exponent) << endl;
}
开发者ID:jeluth,项目名称:Data-Structures-Materials,代码行数:14,代码来源:polytest0.cpp

示例10: quo_rem

    std::pair<polynomial, polynomial> quo_rem (polynomial divisor) const {
        /* Degrees of the remainder and quotient. */
        int kd = divisor.degree();
        int kr = kd - 1;
        int kq = degree() - kd;

        std::vector<double> remainder (kr + 1);
        std::vector<double> quotient (kq + 1);

        auto dbegin = divisor.coefficients.crbegin() + 1;
        auto dend = divisor.coefficients.crend();
        auto qbegin = quotient.end();
        auto qend = quotient.end();

        for (int i = kq; 0 <= i; i--) {
            quotient[i] = (coefficients[kd+i] - ip(dbegin, dend, qbegin, qend)) / divisor[kd];
            --qbegin;
        }

        for (int i = kr; 0 <= i; i--) {
            remainder[i] = coefficients[i] - ip(dbegin, dend, qbegin, qend);
            ++dbegin;
        }

        return { polynomial { quotient }, polynomial { remainder } };
    }
开发者ID:harrishancock,项目名称:nummeth,代码行数:26,代码来源:polynomial.hpp

示例11: while

void polynomial::div_and_mod(const polynomial &p, 
		polynomial &result, polynomial &remainder) const {
	remainder = *this;

	while (!remainder.islower(p)) {
		double coe = remainder.beg->coe / p.beg->coe;
		double exp = remainder.beg->exp - p.beg->exp;
		if (coe == 0) break;

		polynomial ans;
		ans.append(coe, exp);
		result.append(coe, exp);

		remainder = remainder.minus(ans.multiply(p));
	}
}
开发者ID:Lw-Cui,项目名称:polynomial,代码行数:16,代码来源:polynomial.cpp

示例12: sturm_functions

        void sturm_functions(std::vector< polynomial<data__> > &sturm_fun, const polynomial<data__> &f)
        {
          size_t i, n;

          // resize the Sturm function vector
          n=f.degree()+1;
          sturm_fun.resize(n);

          polynomial<data__> *ptemp(f.fp()), pjunk;

          // initialize the Sturm functions
          sturm_fun[0]=f;
          ptemp=f.fp();
          sturm_fun[1]=*ptemp;
          delete ptemp;

          // build the Sturm functions
          sturm_fun[0].divide(std::abs(sturm_fun[0].coefficient(sturm_fun[0].degree())));
          sturm_fun[1].divide(std::abs(sturm_fun[1].coefficient(sturm_fun[1].degree())));
          for (i=2; i<n; ++i)
          {
            if (sturm_fun[i-1].degree()>0)
            {
              data__ small_no, max_c(0);
              typename polynomial<data__>::coefficient_type c;

              sturm_fun[i-1].get_coefficients(c);
              for (typename polynomial<data__>::index_type j=0; j<=sturm_fun[i-1].degree(); ++j)
              {
                if (std::abs(c(j))>max_c)
                  max_c=std::abs(c(j));
              }
              small_no=max_c*std::sqrt(std::numeric_limits<data__>::epsilon());

              pjunk.divide(sturm_fun[i], sturm_fun[i-2], sturm_fun[i-1]);
              sturm_fun[i].negative();
              if (std::abs(sturm_fun[i].coefficient(sturm_fun[i].degree()))>small_no)
                sturm_fun[i].divide(std::abs(sturm_fun[i].coefficient(sturm_fun[i].degree())));
              sturm_fun[i].adjust_zero(small_no);
            }
            else
            {
              sturm_fun[i]=0;
            }
          }
        }
开发者ID:bclarksoftware,项目名称:Code-Eli,代码行数:46,代码来源:sturm_count.hpp

示例13: find_kernels

void find_kernels(const polynomial& P, vector<pair<monomial, polynomial>>& kernelmap)
{
    kernelmap.clear();
    kernels(0, P, monomial(), kernelmap);
    if (P.gcd() == monomial())
    {
        kernelmap.push_back(make_pair(monomial(), P));
    }
}
开发者ID:zxrlha,项目名称:wpo,代码行数:9,代码来源:kernel.cpp

示例14: descartes_rule

        int descartes_rule(const polynomial<data__> &f, bool positive)
        {
          // catch special case
          if (f.degree()==0)
            return 0;

          // get the coefficients from the polynomial
          std::vector<data__> a(f.degree()+1);
          for (size_t i=0; i<a.size(); ++i)
          {
            a[i]=f.coefficient(i);

            // change the sign of odd powers if want the negative root count
            if (!positive && i%2==1)
              a[i]*=-1;
          }

          return eli::mutil::poly::root::sign_changes(a.begin(), a.end());
        }
开发者ID:bclarksoftware,项目名称:Code-Eli,代码行数:19,代码来源:descartes_rule.hpp

示例15: ans

polynomial operator + (const polynomial &p, const polynomial &q) {
	polynomial::const_iterator itP, itQ;
	polynomial C;
	itP = p.begin();
	itQ = q.begin();
	while(itP != p.end() && itQ != q.end()) {
		if ((*itP).second == (*itQ).second) {
			term ans(((*itP).first + (*itQ).first), (*itQ).second);
			if (((*itP).first + (*itQ).first) != 0) 
				C.push_back(ans);
			itP++;
			itQ++;
			
		} else if ((*itP).second < (*itQ).second) {
			C.push_back(*itQ);
			itQ++;
		} else {
			C.push_back(*itP);
			itP++;
		}
	}
	while (itP != p.end()) {
		C.push_back(*itP);
		itP++;
	}
	while (itQ != q.end()) {
		C.push_back(*itQ);
		itQ++;
	}


	return C;

}
开发者ID:stella1006,项目名称:Algorithm,代码行数:34,代码来源:多项式的表示和运算.cpp


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