Exemple #1
0
        public override Node Derivative()
        {
            e     e = new e(this.leftChild);
            multi m = new multi(e, this.leftChild.Derivative());

            return(m.Simplify());
        }
Exemple #2
0
 public override Node Derivative()
 {
     power p = new power(this.leftChild, new digits((Convert.ToInt32(this.rightChild.inside) - 1).ToString()));
     multi m = new multi(p, new digits(this.rightChild.inside));
     multi m1 = new multi(m, this.leftChild.Derivative());
     return m1;
 }
Exemple #3
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);
 }
Exemple #4
0
 public override Node Simplify()
 {
     this.leftChild = leftChild.Simplify();
     if (this.leftChild is digits)
     {
         if (this.leftChild.inside == "1")
         {
             return(new digits("0"));
         }
         if (Convert.ToDouble(this.leftChild.inside) < 1)
         {
             throw new MyException("Ln can be less than 1!");
         }
     }
     else if (this.leftChild is e)
     {
         return(new digits(this.leftChild.leftChild.inside));
     }
     else if (this.leftChild is power)
     {
         ln    l = new ln(this.leftChild.leftChild);
         multi m = new multi(this.leftChild.rightChild, l);
         return(m);
     }
     return(this);
 }
Exemple #5
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 new digits("1");
     }
     else if (this.rightChild is digits && this.rightChild.inside == "1")
     {
         return this.leftChild;
     }
     else if (this.rightChild is digits && this.rightChild.inside == "0")
     {
         return new digits("1");
     }
     else if (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((Math.Pow(Convert.ToDouble(this.leftChild.inside), Convert.ToDouble(this.rightChild.inside))).ToString());
     }
     else if (this.leftChild is e)
     {
         multi m = new multi(this.leftChild.leftChild, this.rightChild);
         return new e(m);
     }
     return this;
 }
Exemple #6
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);
        }
Exemple #7
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);
        }
Exemple #8
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);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        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);
        }
Exemple #11
0
        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);
        }
Exemple #12
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);
        }
Exemple #13
0
 public override Node Simplify()
 {
     this.leftChild  = this.leftChild.Simplify();
     this.rightChild = this.rightChild.Simplify();
     if (this.rightChild is digits && this.rightChild.inside == "0")
     {
         return(this.leftChild);
     }
     else if (this.leftChild is digits && this.leftChild.inside == "0")
     {
         return(this.rightChild);
     }
     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 is ln && this.leftChild is ln)
     {
         multi m = new multi(this.leftChild.leftChild, this.rightChild.leftChild);
         return(new ln(m));
     }
     return(this);
 }
Exemple #14
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);
        }