Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 public override Node Simplify()
 {
     this.leftChild  = this.leftChild.Simplify();
     this.rightChild = this.rightChild.Simplify();
     if (this.leftChild is digits && this.leftChild.inside == "1")
     {
         return(this.rightChild);
     }
     else if (this.rightChild is digits && this.rightChild.inside == "1")
     {
         return(this.leftChild);
     }
     else if ((this.rightChild is digits && this.rightChild.inside == "0") || (this.leftChild is digits && this.leftChild.inside == "0"))
     {
         return(new digits("0"));
     }
     else if (this.rightChild is digits && this.leftChild is digits)
     {
         return(new digits((Convert.ToInt32(this.leftChild.inside) * Convert.ToInt32(this.rightChild.inside)).ToString()));
     }
     else if (this.rightChild is e && this.leftChild is e)
     {
         plus p = new plus(this.leftChild.leftChild, this.rightChild.leftChild);
         return(new e(p));
     }
     else if (this.rightChild is minus && this.leftChild is minus && this.rightChild.rightChild is null && this.leftChild.rightChild is null)
     {
         multi m = new multi(this.rightChild.leftChild, this.leftChild.leftChild);
         return(m);
     }
     return(this);
 }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public override Node Derivative()
        {
            multi f1 = new multi(this.leftChild.Derivative(), this.rightChild);
            multi f2 = new multi(this.leftChild, this.rightChild.Derivative());
            plus  p  = new plus(f1, f2);

            return(p);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        public override Node Derivative()
        {
            plus p = new plus(leftChild.Derivative(), rightChild.Derivative());

            return(p);
        }
Esempio n. 7
0
        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);
        }