public static double Tailor(MathBinaryTree eq, double[,] pTable , int rank)
 {
     double h = pTable[0,1]-pTable[0,0];
     if (rank == 0) {
         return pTable[1,0];
     }
     else {
         return 0;
     }
 }
Esempio n. 2
0
 public MainForm()
 {
     InitializeComponent();
     //double[,] pt = new double[2, 7];
     //pt[0, 0] = 30; pt[1, 0] = 0.5;
     //pt[0, 1] = 35; pt[1, 1] = 0.5736;
     //pt[0, 2] = 40; pt[1, 2] = 0.6428;
     //pt[0, 3] = 45; pt[1, 3] = 0.7071;
     //pt[0, 4] = 50; pt[1, 4] = 0.7660;
     //pt[0, 5] = 55; pt[1, 5] = 0.8192;
     //pt[0, 6] = 60; pt[1, 6] = 0.8660;
     //MessageBox.Show(Functions.Postfix("a+c+b"));
     MathBinaryTree te = new MathBinaryTree("5+x");
     MathBinaryTree dte = te.Drive(te.Root);
     double[,] pt = new double[2, 7];
     pt[0, 0] = 30; pt[1, 0] = 0.5;
     pt[0, 1] = 35; pt[1, 1] = 0.5736;
     pt[0, 2] = 40; pt[1, 2] = 0.6428;
     pt[0, 3] = 45; pt[1, 3] = 0.7071;
     pt[0, 4] = 50; pt[1, 4] = 0.7660;
     pt[0, 5] = 55; pt[1, 5] = 0.8192;
     pt[0, 6] = 60; pt[1, 6] = 0.8660;
     MessageBox.Show(@"Rectangles method : " + Integration.Rects(pt).ToString() + @" , Trapezoid method : " + Integration.Trapezoid(pt).ToString() + @" , Simpson method : "+ Integration.Simpson(pt).ToString());
 }
        /// <summary>
        /// Eval the specified value of function.
        /// </summary>
        /// <param name='val'>
        /// Value.
        /// </param>
        public double Eval(double val)
        {
            double res = 0;
            MathBinaryTree tmpTree = new MathBinaryTree();
            tmpTree.Clone(this);
            for (int i = 0; i < Nodes.Count; i++)
            {
                if (this[i] != null && this[i].Op != Operator.None)
                {
                    switch (this[i].Op)
                    {
                        case Operator.Pow:
                            res = Math.Pow(this[this[i].Lchild].Num, this[this[i].Rchild].Num);
                            this[i].Create(res, this[i].ParentId);
                            break;
                        case Operator.Mult:
                            res = this[this[i].Lchild].Num * this[this[i].Rchild].Num;
                            this[i].Create(res, this[i].ParentId);
                            break;
                        case Operator.Sum:
                            res = this[this[i].Lchild].Num + this[this[i].Rchild].Num;
                            this[i].Create(res, this[i].ParentId);
                            break;
                        case Operator.Sub:
                            res = this[this[i].Lchild].Num - this[this[i].Rchild].Num;
                            this[i].Create(res, this[i].ParentId);
                            break;
                        case Operator.Div:
                            res = this[this[i].Lchild].Num / this[this[i].Rchild].Num;
                            this[i].Create(res, this[i].ParentId);
                            break;
                        case Operator.Abs:
                            res = Math.Abs(this[this[i].Rchild].Num);
                            this[i].Create(res, this[i].ParentId);
                            break;
                        case Operator.Acos:
                            res = Math.Acos(this[this[i].Rchild].Num);
                            this[i].Create(res, this[i].ParentId);
                            break;
                        case Operator.Cos:
                            res = Math.Cos(this[this[i].Rchild].Num);
                            this[i].Create(res, this[i].ParentId);
                            break;
                        case Operator.ASin:
                            res = Math.Asin(this[this[i].Rchild].Num);
                            this[i].Create(res, this[i].ParentId);
                            break;
                        case Operator.Atan:
                            res = Math.Atan(this[this[i].Rchild].Num);
                            this[i].Create(res, this[i].ParentId);
                            break;
                        case Operator.Cosh:
                            res = Math.Cosh(this[this[i].Rchild].Num);
                            this[i].Create(res, this[i].ParentId);
                            break;
                        case Operator.Sin:
                            res = Math.Sin(this[this[i].Rchild].Num);
                            this[i].Create(res, this[i].ParentId);
                            break;
                        case Operator.Tan:
                            res = Math.Tan(this[this[i].Rchild].Num);
                            this[i].Create(res, this[i].ParentId);
                            break;
                        case Operator.Cot:
                            res = 1 / Math.Tan(this[this[i].Rchild].Num);
                            this[i].Create(res, this[i].ParentId);
                            break;
                        case Operator.Ln:
                            res = Math.Log(this[this[i].Rchild].Num);
                            this[i].Create(res, this[i].ParentId);
                            break;
                        case Operator.Exp:
                            res = Math.Exp(this[this[i].Rchild].Num);
                            this[i].Create(res, this[i].ParentId);
                            break;
                    }

                }
                else if (this[i].Varname != '\0')
                {
                    this[i].Varname = '\0';
                    this[i].Num = val;
                }
            }
            this.Clone(tmpTree);
            return res;
        }
 public void Clone(MathBinaryTree Original)
 {
     this.Nodes.Clear();
     foreach (MathNode Node in Original.Nodes)
     {
         if (Node != null)
         {
             MathNode t = new MathNode();
             t = Node.Clone();
             this.Nodes.Add(t);
         }
     }
     this.Root = Original.Root;
 }
Esempio n. 5
0
 private void TxtbxMathExpressionLeave(object sender, EventArgs e)
 {
     if ((((TextBox)sender).Text == @"Enter mathematical expression") || (((TextBox)sender).Text == ""))
     {
         ((TextBox)sender).Text = @"Enter mathematical expression";
         ((TextBox)sender).Font = txtbxInactive.Font;
         ((TextBox)sender).ForeColor = txtbxInactive.ForeColor;
     }
     else
     {
         if (txtbxVariable.Text == "")
         {
             _mathEx = new MathBinaryTree(txtbxMathExpression.Text);
         }
         else
         {
             _mathEx = new MathBinaryTree(txtbxMathExpression.Text,txtbxVariable.Text);
         }
         InitilizePtable();
     }
 }