static void Main(string[] args) { /////////////////////////////////////////// Console.WriteLine("Введите члены полинома"); Polynomial Pol = new Polynomial(Filling()); Console.WriteLine("Введите х"); double X = Convert.ToDouble(Console.ReadLine()); Pol.Print(); Console.WriteLine("Полином равен =" + Pol.Calc(X)); Console.WriteLine("Введите члены полинома"); Polynomial Pol1 = new Polynomial(Filling()); Polynomial Pol_ret = new Polynomial(); Pol_ret = Pol + Pol1; Console.WriteLine("Сумма двух полиномов: "); Pol_ret.Print(); Pol_ret = Pol - Pol1; Console.WriteLine("Разность двух полиномов: "); Pol_ret.Print(); Pol_ret = Pol * Pol1; Console.WriteLine("Произведение двух полиномов: "); Pol_ret.Print(); Console.WriteLine("Введите значение, на которое нужно умножить члены полинома"); double var = Convert.ToDouble(Console.ReadLine()); Pol_ret = Pol * var; Console.WriteLine("Полином, после умножения на него числа: "); Pol_ret.Print(); ///////////////////////////////////////////////// double x = Convert.ToDouble(Console.ReadLine()); LaGranges_Polynomial LaG_P = new LaGranges_Polynomial(x); LaG_P.Print(); Console.ReadLine(); }
public static Polynomial operator /(Polynomial Pol, double var) { Polynomial Pol_ret = new Polynomial(); int max_index = Pol.max_not_zero(); try { for (int i = 0; i <= max_index; i++) { if (Pol.Arr[i] == 0) { continue; } Pol_ret.Arr[i] = Pol.Arr[i] / var; } } catch(DivideByZeroException) { } return Pol_ret; }
public static Polynomial operator -(Polynomial Pol, double var) { Polynomial Pol_ret = new Polynomial(); Pol_ret.Arr[0] = Pol_ret.Arr[0] - var; return Pol_ret; }
public static Polynomial operator -(Polynomial Pol, Polynomial Pol1) { Polynomial Pol_ret = new Polynomial(); for (int i = 0; i < twhnd; i++) { Pol_ret.Arr[i] = Pol.Arr[i] - Pol1.Arr[i]; } return Pol_ret; }
public static Polynomial operator +(Polynomial Pol, Polynomial Pol1) { Polynomial Pol_ret = new Polynomial(); for ( int i = 0; i < twhnd; i++) { if ((Pol.Arr[i] == 0) && (Pol1.Arr[i] == 0)) { continue; } Pol_ret.Arr[i] = Pol.Arr[i] + Pol1.Arr[i]; } return Pol_ret; }
public static Polynomial operator *(Polynomial Pol0, Polynomial Pol1) { try { Polynomial Pol_ret = new Polynomial(); int max0_index = Pol0.max_not_zero(); int max1_index = Pol1.max_not_zero(); for (int i = 0; i <= max0_index; i++) { for (int j = 0; j <= max1_index; j++) { Pol_ret.Arr[i + j] += Pol0.Arr[i] * Pol1.Arr[j]; } } return Pol_ret; } catch(StackOverflowException) { Polynomial Pol_err = new Polynomial(); return Pol_err; } }