/*public static Polinom operator *(Polinom a, Matrix b) * { * Polinom res = new Polinom(); * foreach (Monom i in a) * { * foreach (Monom j in b) * { * res.monoms.Add(* j); * } * } * return res; * }*/ public static Polinom operator/(Polinom a, Polinom b) { Polinom res = new Polinom(); if (a.monoms[0].degree < b.monoms[0].degree) { return(null); } Monom tmp = a.monoms[0] / b.monoms[0]; res.monoms.Add(tmp); Polinom pol = a - (new Polinom(tmp) * b).ReducedPolinom(); foreach (Monom i in pol) { foreach (double elem in i.coeff) { if (elem != 0) { res.monoms.AddRange((pol / b).monoms); } } } return(res); }
static void Main(string[] args) { Matrix m = new Matrix(2); //Console.WriteLine(m); Matrix n = (Matrix)m.Clone(); m.array[0, 0] = 0; //Console.WriteLine(n); //Console.WriteLine(); List <Monom> l = new List <Monom> { new Monom(new Matrix(2.0), "x", 3), new Monom(new Matrix(2.5), "x", 1) }; Polinom p1 = new Polinom(l); Polinom p2 = new Polinom(l); //Console.WriteLine(p1 + "\n"); Console.WriteLine(p2 * p1); Console.WriteLine(p2.CompareTo(p1)); Console.WriteLine(m.CompareTo(n)); //Console.WriteLine(Polinom.Compose(p1, p2).ReducedPolinom()); }
public static Polinom Pow(Polinom a, int degree) { Polinom result = (Polinom)a.Clone(); for (var i = 0; i < degree - 1; i++) { result = result * a; } return(result); }
public static Polinom operator+(Polinom a, Polinom b) { Polinom res = new Polinom(); foreach (Monom i in a) { res.monoms.Add(i); } foreach (Monom j in b) { res.monoms.Add(j); } return(res.ReducedPolinom()); }
public static Polinom operator*(Polinom a, Polinom b) { Polinom res = new Polinom(); foreach (Monom i in a) { foreach (Monom j in b) { res.monoms.Add(i * j); Console.WriteLine(res); } } return(res.ReducedPolinom()); }
public static Polinom Compose(Polinom a, Polinom b) { Polinom result = new Polinom(); foreach (Monom monA in a.monoms) { Polinom pol = Polinom.Pow(b, monA.degree); foreach (Monom monB in pol) { result.monoms.Add(new Monom(monA.coeff * monB.coeff, monA.symbol, monB.degree)); } } return(result.ReducedPolinom()); }
public int CompareTo(object obj1) { if (obj1.GetType() != typeof(Polinom)) { throw new MatrixException("Невозможно сравнить"); } Polinom pol2 = (Polinom)obj1; foreach (Monom i in this.monoms) { foreach (Monom j in pol2) { if (i.degree == j.degree) { return(i.coeff.CompareTo(j.coeff)); } } } return(0); }