public override Node Simplify() { this.leftChild = this.leftChild.Simplify(); this.rightChild = this.rightChild.Simplify(); if (this.leftChild is digits && this.leftChild.inside == "0") { return(new digits("0")); } else if (this.rightChild is digits && this.rightChild.inside == "1") { return(this.leftChild); } else if (this.rightChild is digits && this.leftChild is digits) { return(new digits((Convert.ToDouble(this.leftChild.inside) / Convert.ToDouble(this.rightChild.inside)).ToString())); } else if (this.rightChild.ToString() == this.leftChild.ToString()) { return(new digits("1")); } else if (this.leftChild is e && this.rightChild is e) { minus m = new minus(this.leftChild.leftChild, this.rightChild.leftChild); return(new e(m)); } return(this); }
public override Node Derivative() { multi f1 = new multi(this.leftChild.Derivative(), this.rightChild); multi f2 = new multi(this.leftChild, this.rightChild.Derivative()); minus m = new minus(f1, f2); power p = new power(this.rightChild, new digits("2")); division d = new division(m, p); return(d); }
public override Node Derivative() { minus m; if (rightChild is null) { m = new minus(new digits("0"), leftChild.Derivative()); return(m); } m = new minus(leftChild.Derivative(), rightChild.Derivative()); return(m); }
public BinaryTree MakePolonomialFunctionLagrange(int[] points) { root = null; int[] x = new int[points.Length / 2]; int[] y = new int[points.Length / 2]; int xat = 0; int yat = 0; for (int i = 0; i < points.Length; i++) { if (i % 2 == 0) { x[xat] = points[i]; xat++; } else { y[yat] = points[i]; yat++; } } for (int i = 0; i < x.Length; i++) { int count = 0; int time = 0; double total = 1; Node temp = null; while (count < x.Length) { if (i != count) { total = total * (x[i] - x[count]); time++; if (time == 1) { variables var = new variables("x"); digits d = new digits(x[count].ToString()); minus m = new minus(var, d); temp = m; } else { variables var = new variables("x"); digits d = new digits(x[count].ToString()); minus m = new minus(var, d); temp = new multi(temp, m); } } count++; } total = y[i] / total; digits d1 = new digits(total.ToString()); multi m1 = new multi(temp, d1); temp = m1; if (i == 0) { root = temp; } else { plus p = new plus(root, temp); root = p; } } root = root.Simplify(); return(this); }