public BinaryTree MakePolonomialFunction(double[] coef) { root = null; int p = coef.Length - 1; for (int i = 0; i < coef.Length; i++) { if (i == 0) { digits d = new digits(coef[i].ToString()); power power = new power(new variables("x"), new digits(p.ToString())); multi m = new multi(d, power); root = m; p--; } else { digits d = new digits(coef[i].ToString()); power power = new power(new variables("x"), new digits(p.ToString())); multi m = new multi(d, power); plus plus = new plus(root, m); root = plus; p--; } } root = root.Simplify(); return(this); }
public BinaryTree CreateMcLaurinAn(string value, int n) { root = null; Node root1 = this.CreateBinaryTree(root, ref value); digits d = new digits(root1.Calculations(0).ToString()); _ fac = new _(new digits("0")); digits d1 = new digits(fac.Calculations(0).ToString()); division div = new division(d, d1); power pow = new power(new variables("x"), new digits("0")); multi m = new multi(div, pow); root = m; for (int i = 1; i <= n; i++) { root1 = root1.Derivative(); digits dd = new digits(root1.Calculations(0).ToString()); _ fac1 = new _(new digits($"{i}")); digits dd1 = new digits(fac1.Calculations(0).ToString()); division div1 = new division(dd, dd1); power pow1 = new power(new variables("x"), new digits($"{i}")); multi m1 = new multi(div1, pow1); plus p = new plus(root, m1); root = p; } return(this); }
public override Node Derivative() { if (this.leftChild is digits) { digits d = new digits("0"); return(d); } multi f1 = new multi(new cos(this.leftChild), this.leftChild.Derivative()); return(f1); }
public override Node Derivative() { if (this.leftChild is digits) { digits d = new digits("0"); return(d); } division d1 = new division(new digits("1"), this.leftChild); multi m = new multi(d1, this.leftChild.Derivative()); return(m); }
public BinaryTree CreateMcLaurinPlotN(string v, int n) { double[] functions = new double[n + 1]; int power = 0; root = null; Node root1 = this.CreateBinaryTree(root, ref v); while (power <= n) { double result = 0; int[] coef = this.coef(power); int powerindex = power; for (int i = 0; i <= power; i++) { result = result + coef[i] * root1.Calculations(powerindex * this.almostzero); powerindex--; } if (power == 0) { functions[power] = result; digits d = new digits(result.ToString()); _ fac = new _(new digits("0")); digits d1 = new digits(fac.Calculations(0).ToString()); division div = new division(d, d1); power pow = new power(new variables("x"), new digits("0")); multi m = new multi(div, pow); root = m; } else { functions[power] = result / Math.Pow(this.almostzero, power); digits dd = new digits(Math.Round(functions[power], 2).ToString()); _ fac1 = new _(new digits($"{power}")); digits dd1 = new digits(fac1.Calculations(0).ToString()); division div1 = new division(dd, dd1); power pow1 = new power(new variables("x"), new digits($"{power}")); multi m1 = new multi(div1, pow1); plus p = new plus(root, m1); root = p; } power++; } //double d = root.Calculations(x + this.almostzero); //double d1 = root.Calculations(x); //double d2 = (d - d1); //double d3 = d2 / this.almostzero; return(this); }
public override Node Derivative() { digits d = new digits("0"); return(d); }
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); }