public poly substitudeY(poly y_x) { for (int i = 0; i < y_x.count; i++) { if (y_x.terms[i].yp > 0) { throw new Exception("y_x is not a function of x!"); } } poly temp = new poly(); temp.addTerm(this); for (int i = 0; i < yp; i++) { for (int j = 0; j < temp.count; j++) { temp.terms[j].yp--; } temp *= y_x; } for (int i = 0; i < temp.count; i++) { if (temp.terms[i].yp > 0) { throw new Exception("yp > 0 after substitude!"); } } return(temp); }
public poly substitudeX(poly x_y) { for (int i = 0; i < x_y.count; i++) { if (x_y.terms[i].xp > 0) { throw new Exception("x_y is not a function of x!"); } } poly temp = new poly(); temp.addTerm(this); for (int i = 0; i < xp; i++) { for (int j = 0; j < temp.count; j++) { temp.terms[j].xp--; } temp *= x_y; } for (int i = 0; i < temp.count; i++) { if (temp.terms[i].xp > 0) { throw new Exception("xp > 0 after substitude!"); } } return(temp); }
public void extend(poly p) { for (int i = 0; i < p.count; i++) { this.addTerm(p.terms[i]); } }
public static poly operator +(poly p1, poly p2) { poly a = new poly(); a.extend(p1); a.extend(p2); return(a); }
public poly(poly p) { count = p.count; for (int i = 0; i < count; i++) { terms[i] = new term(p.terms[i]); } }
public static poly operator -(poly p1, poly p2) { poly a = new poly(); term neg = new term(-1); a.extend(p1); a.extend(neg * p2); return(a); }
public static poly operator *(poly p1, poly p2) { poly result = new poly(); for (int i = 0; i < p1.count; i++) { result += p1.terms[i] * p2; } return(result); }
public static poly operator *(poly p, term t) { poly result = new poly(p); for (int i = 0; i < p.count; i++) { result.terms[i] *= t; } return(result); }
public poly integralY() { poly temp = new poly(); for (int i = 0; i < count; i++) { temp.addTerm(terms[i].integralY()); } return(temp); }
public poly substitudeX(poly x_y) { poly temp = new poly(); for (int i = 0; i < count; i++) { temp += terms[i].substitudeX(x_y); } return(temp); }
public poly substitudeY(poly y_x) { poly temp = new poly(); for (int i = 0; i < count; i++) { temp += terms[i].substitudeY(y_x); } return(temp); }
static poly pol(int[,] termData) { poly p = new poly(); for (int i = 0; i < termData.GetLength(0); i++) { p.addTerm(ter(termData[i, 0], termData[i, 1], termData[i, 2])); } return(p); }
static void test2() { poly f = pol(ter(2, 2, 1)); poly z = pol(new int[, ] { { 4, 0, 0 }, { -1, 2, 0 }, { -1, 0, 2 } }); f.extend(pol(ter(2, 0, 2)) * z); f.extend(pol(ter(1, 1, 0)) * z); doubleItgYX(f, pol(ter(0)), pol(ter(1)), fra(0), fra(1)).print(); }
static void test() { poly f = pol(new int[, ] { { 1, 1, 0 }, { 1, 0, 1 } }); poly x = new poly(ter(fra(1, 6), 1)); poly y_x1 = pol(new int[, ] { { 3, 0, 0 }, { -1, 1, 0 } }); poly y_x0 = new poly(ter(fra(1, 2), 1)); doubleItgYX(x * f, y_x0, y_x1, fra(0), fra(2)).print(); }
static frac doubleItgYX(poly f, poly y_x0, poly y_x1, frac x0, frac x1) { frac res = new frac(0); f.print(); poly iy_f = f.integralY(); iy_f.print(); poly f_x = iy_f.substitudeY(y_x1) - iy_f.substitudeY(y_x0); f_x.print(); poly F = f_x.integralX(); F.print(); res = F.value(x1, new frac(0)) - F.value(x0, new frac(0)); return(res); }