/// <summary>
        /// Crates polynom from tree
        /// </summary>
        /// <param name="tree">Tree</param>
        /// <returns>Polynom</returns>
        public double[] CreatePolynom(ObjectFormulaTree tree)
        {
            val = 0;
            ObjectFormulaTree t     = tree;
            List <double>     l     = new List <double>();
            double            coeff = 1;

            for (int i = 0; i < maxorder; i++)
            {
                if (t == ElementaryRealConstant.RealZero)
                {
                    break;
                }
                double a = (double)t.Result;
                a     /= coeff;
                coeff *= (double)(i + 1);
                l.Add(a);
                ObjectFormulaTree tr = t;
                t = t.Derivation(arg);
            }
            if (t != ElementaryRealConstant.RealZero)
            {
                throw new Exception("This not a polynom");
            }
            return(l.ToArray());
        }
Ejemplo n.º 2
0
        private void buttonCalc_Click(object sender, EventArgs e)
        {
            // try
            // {
            MathFormula f = new MathFormula(panel.Performer.Formula, UndrawableConverter.Object);

//                MathFormula f = MathFormula.FromString(panel.Performer.Formula.Sizes, fs);
            f = f.FullTransform(null);

            /*FormulaTree tree = new FormulaTree(f);
             * FormulaTree der = tree.Deriv(textBoxDerivType.Text);
             * der.SimplifyAll();
             * derivFormula = der.GetFormula(0, FormulaEditorPanel.sizes);*/
            ObjectFormulaTree tree = ObjectFormulaTree.CreateTree(f, ElementaryFunctionsCreator.Object);
            ObjectFormulaTree der  = tree.Derivation(textBoxDerivType.Text);
            //der = ElementaryFormulaSimplification.Object.Simplify(der);//der.SimplifyAll();
            MathFormula form = FormulaCreator.CreateFormula(der, (byte)0, MathSymbolFactory.Sizes);

            form.Simplify();

            derivFormula          = new MathFormulaDrawable(form, DrawableConverter.Object);
            derivFormula.Position = pointDeriv;
            derivFormula.CalculateFullRelativeRectangle();
            derivFormula.CalculatePositions();
            paintDeriv();
            Refresh();

            /*    }
             *  catch (System.Exception ex)
             *  {
             *      WindowsExtensions.ControlExtensions.ShowMessageBoxModal(this, ex.Message);
             *  }*/
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates measure
        /// </summary>
        /// <param name="tree">Tree</param>
        /// <param name="n">Number of tree</param>
        /// <param name="name">Name</param>
        /// <param name="associated">Associated addition</param>
        /// <returns>Measurement</returns>
        public static FormulaMeasurement Create(ObjectFormulaTree tree, int n,
                                                string name, AssociatedAddition associated)
        {
            object ret = null;

            try
            {
                ret = tree.Result;
            }
            catch (Exception ex)
            {
                ex.ShowError(-1);
            }
            FormulaMeasurement fm;

            if (n == 0)
            {
                IDistribution d = DeltaFunction.GetDistribution(tree);
                if (d != null)
                {
                    return(new FormulaMeasurementDistribution(tree, name, associated));
                }
                fm     = new FormulaMeasurement(tree, name, associated);
                fm.ret = ret;
                return(fm);
            }
            string            dn = "D" + name;
            ObjectFormulaTree t  = tree.Derivation("d/dt");

            if (t == null)
            {
                throw new Exception("VariableMeasure.Derivation");
            }
            AssociatedAddition aa  = FormulaMeasurementDerivation.Create(associated);
            FormulaMeasurement der = Create(t, n - 1, dn, aa);

            fm = new FormulaMeasurementDerivation(tree, der, name, aa);
            try
            {
                fm.ret = t.Result;
            }
            catch (Exception exc)
            {
                exc.ShowError(10);
            }
            return(fm);
        }