Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }