本文整理汇总了C++中Polynomial::deg方法的典型用法代码示例。如果您正苦于以下问题:C++ Polynomial::deg方法的具体用法?C++ Polynomial::deg怎么用?C++ Polynomial::deg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polynomial
的用法示例。
在下文中一共展示了Polynomial::deg方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mniejszy
Polynomial mniejszy(Polynomial q, Polynomial p) //zwraca wielomian nizszego stopnia
{
if(p.deg()<=q.deg())
return p;
else
return q;
}
示例2: quotient_coefficients
inline void Polynomial<T, Structure>::divide(const Polynomial<T, Structure>& divisor, Polynomial<T, Structure>& quotient, Polynomial<T, Structure>& remainder) const
{
if (deg() < divisor.deg()) {
remainder = *this;
quotient = zero();
return;
}
size_type divisor_deg = divisor.deg();
size_type new_deg = deg() - divisor_deg;
remainder = *this;
if (deg() < divisor_deg) {
quotient = one();
return;
}
coefficient_list quotient_coefficients (new_deg + 1);
const T divisor_first_digit = divisor.m_coefficients[divisor_deg];
for (size_type i = new_deg + 1; i > 0;) {
--i;
quotient_coefficients[i] = remainder.m_coefficients[i + divisor_deg] / divisor_first_digit;
Polynomial<T, Structure> factor (m_structure, quotient_coefficients[i], i);
Polynomial<T, Structure> back_calculated = factor * divisor;
remainder.subtract(back_calculated);
}
remainder.remove_zeros();
quotient = Polynomial<T, Structure>(m_structure, quotient_coefficients);
}
示例3: wiekszy
Polynomial wiekszy(Polynomial q, Polynomial p) //zwraca wielomian wyzszego stopnia
{
if(p.deg()>=q.deg())
return p;
else
return q;
}
示例4: value
double value(Polynomial p, double x)
{
//wartoϾ w a = reszcie z p/(x-a)
double m=p.getA(p.deg());
for(int i = p.deg()-1; i >= 0; i--)
m=m*x+p.getA(i);
return m;
}
示例5: add
Polynomial add(Polynomial q, Polynomial p)
{
int stW;
stW = max(q.deg(), p.deg());
Polynomial w;
for(int i=0; i <= stW; i++)
w.setA(i, p.getA(i)+q.getA(i));
return w;
}
示例6: new_coefficients
inline Polynomial<T, Structure>& Polynomial<T, Structure>::operator*=(const Polynomial<T, Structure>& other)
{
coefficient_list new_coefficients (deg() + other.deg() + 1, 0);
for (size_type i = 0; i <= deg(); ++i) {
for (size_type j = 0; j <= other.deg(); ++j) {
new_coefficients[i + j] += m_coefficients[i] * other.m_coefficients[j];
}
}
m_coefficients = new_coefficients;
remove_zeros();
return *this;
}
示例7: div
void div(const Polynomial &W, const Polynomial &P, Polynomial &Q, Polynomial &R){
R = W;
for(int i=R.deg();i>=0 && R.deg()>=P.deg();i--){
Q.setA(i-P.deg(), R.getA(i)/P.getA(P.deg()));
for(int a=P.deg();a>=0;a--){
R.setA((i-P.deg())+a, R.getA((i-P.deg())+a)-( P.getA(a) * Q.getA(i-P.deg()) ) );
}
}
}
示例8: mult
Polynomial mult(Polynomial q, Polynomial p)
{
Polynomial w;
int h=0; //chwilowa wartoϾ w[i]
for(int i = (q.deg()+p.deg()); i >= 0; i--)
{
for(int j = max(p.deg(), q.deg()); j >= 0; j--)
{
h=h+(wiekszy(p, q).getA(j)*mniejszy(p,q).getA(i-j));
}
w.setA(i, h);
h=0;
}
return w;
}
示例9: subtract
inline Polynomial<T, Structure>& Polynomial<T, Structure>::operator-=(const Polynomial<T, Structure>& other)
{
pad_zeros(other.deg() + 1);
subtract(other);
remove_zeros();
return *this;
}
示例10:
bool Polynomial::operator==(const Polynomial &q) const{
if(deg()!=q.deg()) return false;
for(int i=0;i<deg();i++){
if(a[i]!=q.a[i]) return false;
}
return true;
}
示例11: mult2
Polynomial mult2(Polynomial p, double x) //mnozy wielomian przez liczbe
{
Polynomial v;
for(int i = 0; i <= p.deg(); i++)
v.setA(i, p.getA(i)*x);
return v;
}
示例12: main
int main()
{
Polynomial p;
p.setA(0,1);
p.setA(1,5);
p.setA(2,0);
p.setA(3,3);
/*p.setA(4,2);
p.setA(5,2);
p.setA(6,0);
p.setA(7,0);*/
p.print();
cout<<endl<<p.deg()<<endl;
Polynomial q;
q.setA(0,0);
q.setA(1,0);
q.setA(2,0);
q.setA(3,0);
/*q.setA(4,0);
q.setA(5,0);
q.setA(6,0);
q.setA(7,0);*/
q.print();
cout<<endl<<q.deg()<<endl;
/*
cout<<endl<<"dodawanie; ";
add(p, q).print();
cout<<endl<<"mnozenie: ";
mult(p, q).print();
cout<<endl<<"wartosc p dla 2; ";
cout<<value(p, 2);
Polynomial wynik;
Polynomial reszta;
div(p, q, wynik, reszta);
cout<<endl<<"DZIELENIE: "<<"wynik: ";
wynik.print();
cout<<" reszta: ";
reszta.print();*/
}
示例13:
bool operator!=(const Polynomial &q) const {
if (deg()==q.deg()) {return false;}
for(int i=1; i<= deg(); i++)
{
if (getA(i)==q.getA(i)) return false;
}
return true;
}
示例14:
vector<double> Polynomial :: rational_roots(Polynomial q)
{
cout<<endl<<"będę zaokrąglał niecałkowite współczynniki"<<endl;
vector<double> r;
vector<int> z;
vector<int> o;
for(int i = 0; i < q.getA(0); i++)
{
if( (int)q.getA(0) % 1 == 0 && (int)q.getA(0) % i == 0)
{
z.push_back(i);
z.push_back(-i);
}
}
for(int i = 0; i < q.getA(q.deg() + 1); i++)
{
if((int)q.getA(q.deg() + 1) % 1 == 0 && (int) q.getA(q.deg() + 1) % i == 0)
{
o.push_back(i);
o.push_back(-i);
}
}
for(int i = 0; i < z.size(); i++)
{
for(int j = 0; j < o.size(); j++)
{
if(value(q, j/i) == 0)
{
r.push_back(j/i);
}
}
}
return r;
}
示例15: div
void div(Polynomial p, Polynomial q, Polynomial &wynik, Polynomial &reszta)
{
int b = p.deg();
Polynomial l;
Polynomial prev_wynik;
for(int i = b-q.deg(); p.deg() >= q.deg(); i--)
{
wynik.setA(i, p.getA(p.deg())/q.getA(q.deg()));
l = mult(q, add(wynik, mult2(prev_wynik, -1)));
p = add(p, mult2(l, -1));
prev_wynik = wynik;
}
reszta = p;
}