Example #1
0
Polynom Polynom::mulByXPowK(long long k)
{
	if (*this != Polynom())
		if (k < 0)
			while (k++ && *this != Polynom())
				if (coefficients.size() > 1)
					coefficients.pop_front();
				else
					coefficients[0] = MegaRational();
		else
			while (k--)
				coefficients.push_front(MegaRational());
	return *this;
}
Example #2
0
pair<Polynom, Polynom> Polynom::divide(const Polynom& _another) const {
	//cout << "i am divide(...)" << endl;
	pair<Polynom, Polynom> result(Polynom(), *this); //result and remainder
	result.first.simplify();
	result.second.simplify();

	while(result.second.pow() >= _another.pow() && (result.second.pow() != 0 || result.second[0] != 0)) {
		//cout << "result: " << result.first << endl;
		//cout << "reminder: " << result.second << endl;
		//cout << "divider: " << _another << endl;

		Polynom t;
		unsigned int i = result.second.pow() - _another.pow();
		t.a.resize(i + 1, 0);
		t.a[i] = result.second[result.second.pow()] / _another[_another.pow()];
		
		//cout << "multiplier: " << t << endl;
		//cout << "let's decrease on: " << t * _another << endl;
		//cout << endl << endl;

		result.first += t;
		result.second -= t * _another;
	}

	//cout << "Summary:" << endl;
	//cout << "result: " << result.first << endl;
	//cout << "reminder: " << result.second << endl;


	return result;
}
Example #3
0
	Polynom Polynom::Differenciate() const
	{
		vector<double> v;
		for (size_t i = 1; i < m_coef.size(); ++i)
		{
			v.push_back(m_coef[i] * i);
		}
		return Polynom(v);
	}
Example #4
0
	Polynom Polynom::Integrate() const
	{
		vector<double> v;
		v.push_back(0);
		for (size_t i = 0; i < m_coef.size(); ++i)
		{
			v.push_back(m_coef[i] / double(i+1));
		}
		return Polynom(v);
	}
Example #5
0
Polynom operator *(const Polynom &p1, const Polynom &p2)
{
	Polynom p1Cpy = p1, p2Cpy = p2, res = Polynom();
	MegaRational p1Coefficient = p1Cpy.factorization(),
		p2Coefficient = p2Cpy.factorization();

	for (long long i = p2Cpy.coefficients.size() - 1; i >= 0; i--)
		res = res + (p1Cpy * p2Cpy.coefficients[i]).mulByXPowK(i);

	return res;
}
Example #6
0
	Polynom Polynom::TimeShift(double shift) const
	{
		vector<double> v;
		Polynom p(*this);
		for (int i = 0; i <= Power(); ++i)
		{
			v.push_back(p(shift) / double(Factorial(i)));
			p = p.Differenciate();
		}
		return Polynom(v);
	}
Example #7
0
Polynom operator /(const Polynom &p1, const Polynom &p2)
{
	Polynom res, _p1 = p1, _p2 = p2;
	if (_p2.getDegree() == 0)
	{
		cout << "Error! Division by zero in Polynom /.";
		return Polynom();
	}

	long long n = _p2.getDegree(), k = _p1.getDegree() - n;
	while (k >= 0)
	{
		res.coefficients.push_back(_p1.coefficients[k + n] / _p2.coefficients[n]);
		for (long long i = k + n; i >= k; i--)
			_p1.coefficients[i] = _p1.coefficients[i] -
			_p2.coefficients[i - k] * res.coefficients[k];
		k--;
	}

	return res;
}
Example #8
0
MegaRational Polynom::factorization()
{
	MegaNatural gcd, lcm = 1;
	MegaRational coefficent;

	if (*this != Polynom())
		return MegaRational();

	gcd = coefficients[coefficients.size() - 1].getNumerator().toMegaNatural();
	for (long long i = coefficients.size() - 2; i >= 0; i--)
		if (coefficients[i] != MegaRational())
			gcd = DiscreteMath::gcd(gcd, coefficients[i].getNumerator().toMegaNatural());

	for (long long i = coefficients.size() - 1; i >= 0; i--)
		lcm = DiscreteMath::lcm(lcm, coefficients[i].getDenominator());

	coefficent = coefficent * MegaRational(MegaInteger(gcd), lcm);

	for (long long i = coefficients.size() - 1; i >= 0; i--)
		coefficients[i] = coefficients[i] * MegaRational(MegaInteger(lcm), gcd);

	return coefficent;
}
Example #9
0
	Polynom Polynom::operator-(const Polynom & poly) const
	{
		return Polynom(*this) -= poly;
	}
	void SignalPolinomialDistort::AcceptSignalValue(const double&signal){
		SendSignalValue(Polynom(signal,m_coefs,m_coefs.size()-1));
	}
Example #11
0
Polynom Polynom::operator -() const {return(Polynom(-(Vec)*this));}
Example #12
0
Polynom & Polynom::operator =(const double constant){return(*this=Polynom((Vec)*this=constant));}
Polynom Polynom::integral(const Polynom &ar)
{
    return Polynom(pimpl->integral(*(ar.pimpl)));
}
Polynom Polynom::proizvodnaya(const Polynom &ar)
{
    return Polynom(pimpl->proizvodnaya(*(ar.pimpl)));
}
Polynom Polynom::operator*(const Polynom &ar)
{
    return Polynom(pimpl->operator*(*(ar.pimpl)));
}
Polynom Polynom::operator+(const Polynom &sum)
{
    return Polynom(pimpl->operator+(*(sum.pimpl)));
}
Example #17
0
Polynom Polynom::operator /(const double constant){return (Polynom((Vec)*this/constant));}