Example #1
0
        public void NewInstance()
        {
            ObjectFunction function = new ObjectFunction(null);
            object         instance = function.NewInstance(null);

            Assert.IsNotNull(instance);
            Assert.IsInstanceOfType(instance, typeof(DynamicObject));
        }
Example #2
0
 public Function(object o)
 {
     if (o is MathFunction)
     {
         mfunc = (MathFunction)o;
         t = typeof(MathFunction);
     }
     else
     {
         ofunc = (ObjectFunction)o;
         t = typeof(ObjectFunction);
     }
 }
Example #3
0
 public void Add(string name, ObjectFunction func)
 {
     Function f = new Function(func);
     functions.Add(name, f);
 }
Example #4
0
        private void generateButton_Click(object sender, EventArgs e)
        {
            model = null;
            alpha = null;
            resultRichTextBox.Text = "";

            double m, d, delta;
            int    n;

            try
            {
                m     = Convert.ToDouble(mTextBox.Text);
                d     = Convert.ToDouble(dTextBox.Text);
                n     = Convert.ToInt32(nTextBox.Text);
                delta = Convert.ToDouble(duTextBox.Text);
            }
            catch (FormatException)
            {
                MessageBox.Show("Введены некорректные данные.", "Ошибка ввода");
                return;
            }

            if (l1RadioButton.Checked)
            {
                functions    = new ObjectFunction[1];
                functions[0] = (u => { return(u); });
                alpha        = new double[1] {
                    0
                };

                objectFunction = Function.LinearFunction1;
                funcType       = Functions.Linear_1;
            }
            else if (l2RadioButton.Checked)
            {
                functions    = new ObjectFunction[2];
                functions[0] = (u => { return(1); });
                functions[1] = (u => { return(u); });
                alpha        = new double[2] {
                    0, 0
                };

                objectFunction = Function.LinearFunction2;
                funcType       = Functions.Linear_2;
            }
            else if (nl1RadioButton.Checked)
            {
                functions    = new ObjectFunction[3];
                functions[0] = (u => { return(1); });
                functions[1] = (u => { return(u); });
                functions[2] = (u => { return(u * u); });

                gradient    = new ObjectFunction[3];
                gradient[0] = (u => { return(1); });
                gradient[1] = (u => { return(u); });
                gradient[2] = (u => { return(u * u); });

                alpha = new double[3] {
                    0, 0, 0
                };

                objectFunction = Function.NonLinearFunction1;
                funcType       = Functions.NonLinear_1;
            }
            else if (nl2RadioButton.Checked)
            {
                functions = new ObjectFunction[2];

                /*functions[0] = (u => { return Math.Sin(u); });
                *  functions[1] = (u => { return Math.Cos(u); });*/

                gradient = new ObjectFunction[2];

                /*gradient[0] = (u => { return Math.Sin(u); });
                *  gradient[1] = (u => { return Math.Cos(u); });*/

                gradient[0] = (u => { return(Math.Pow(u, alpha[1])); });
                gradient[1] = (u => { return(alpha[0] * Math.Pow(u, alpha[1]) * Math.Log(u)); });

                alpha = new double[2] {
                    0, 0
                };

                objectFunction = Function.NonLinearFunction2;
                funcType       = Functions.NonLinear_2;
            }
            else
            {
                MessageBox.Show("Выберите объект");
                return;
            }

            adaptButton.Enabled = true;
            showButton.Enabled  = true;

            originalObject = new Dictionary <double, double>();

            for (double i = 0.01; i < delta * n; i += delta)
            {
                originalObject.Add(i, objectFunction(i) + Statistics.MpcGenerator(m, 0, d, 1)[0]);
            }
        }