S
S
Silence2019-01-12 16:10:36
C++ / C#
Silence, 2019-01-12 16:10:36

How to find the roots of a polynomial (polynomial) real and complex C++?

Can you please tell me how to implement the function of finding complex and real roots of a polynomial?
I've read so much and I can't figure it out.

class Polynom{
  private: 
    int deg; //степень полинома
    double *koef; //указатель на массив коэффициентов полинома
  public:
    Polynom();//конструктор без параметром
    Polynom(int);//конструктор с параметром
    Polynom(int, double *);//конструктор с параметрами
    Polynom(const Polynom &);//копирующий конструктор
    ~Polynom(){ delete[] koef;} //деструктор

    int getDegree(); //Порядок полинома
   	double getKoef(unsigned int ); //Получить i-тый коэфф
    void setKoef(int, double);//Изменить i-тый коэфф
    double searchPoly(double);//Значение полинома при x-аргументе
    Polynom getDarivative(unsigned int);//Производная нужного порядка
    double Integrate(double,double);
    Polynom indefiniteIntegral() const;
    
    Polynom operator+(Polynom&);//Сложение двух полиномов
        Polynom operator-(Polynom&);//Вычитание двух полиномов
        Polynom operator=(const Polynom&);//Присваивание 
        Polynom operator*(Polynom&);//Умножение двух полиномов
        Polynom operator/(Polynom &);//деление двух полиномов
        Polynom operator%(Polynom &);//остаток от деления
    
    void InputPolynom(int, double *); //Ввод полинома
    friend ostream& operator<<(ostream&, Polynom&);//Вывод в поток		
};

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zuko3d, 2019-01-13
@zuko3d

If numerical methods can be used, then Newton's method can be modified to work with complex ones too (divide rectangular areas in half). To determine the number of roots in an interval like the Sturm method should help. For the starting interval, I propose to take (FLOAT_MIN; FLOAT_MAX) along both axes (real and imaginary).
For convenience, I propose to write an auxiliary class for working with complex numbers (or take it from GMP, if you can use third-party libraries).
If you need a "direct" solution without FMs, then Abel in the 17th century showed that this is a "task for a peasant" (not expressed in rational functions and radicals). But there is hope: https://ru.wikipedia.org/wiki/%D0%9A%D0%BE%D1%80%D...(True, I only heard about it at lectures and didn’t use it in my life, so xs, how relevant).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question