// Усовершенствованый метод Эйлера
        private void performTheImprovedEulerMethod(double a, double b, function func, int n, double x0, double y0)
        {
            double length = b - a;
            double h      = length / n;

            textBoxResultH.Text += "h = " + h + "\r\n";
            int roundNumber = 8;

            h = h.Truncate(roundNumber) + Math.Pow(10, -roundNumber);
            textBoxResultH.Text += "h = " + h + "\r\n";

            n = n + 1;

            double[] y = new double[n];
            y[0] = y0;
            double[] x = new double[n];
            x[0] = x0;

            for (int i = 1; i < n; i++)
            {
                x[i] = x[i - 1] + h;
                y[i] = y[i - 1] + h * (func(x[i - 1], y[i - 1]) + h / 2 * (getDerivativeX(y[i - 1]) + getDerivativeY(x[i - 1], y[i - 1]) * func(x[i - 1], y[i - 1])));
            }

            printArr(y, "y3", n);
        }
Example #2
0
 public static void addToFrame(object key, function fun)
 {
     if (frameLoopDic.ContainsKey(key) == false)
     {
         frameLoopDic[key] = fun;
     }
 }
        // Метод средней точки
        private void performMidpointMethod(double a, double b, function func, int n, double x0, double y0)
        {
            double length = b - a;
            double h      = length / n;

            textBoxResultH.Text += "h = " + h + "\r\n";
            int roundNumber = 8;

            h = h.Truncate(roundNumber) + Math.Pow(10, -roundNumber);
            textBoxResultH.Text += "h = " + h + "\r\n";

            n = n + 1;

            double[] y = new double[n];
            y[0] = y0;
            double[] x = new double[n];
            x[0] = x0;

            for (int i = 0; i < n - 1; i++)
            {
                double innerFunction = func(x[i], y[i]);
                y[i + 1] = y[i] + h * func(x[i] + h / 2, y[i] + (h / 2) * innerFunction);
                x[i + 1] = x[i] + h;
            }

            printArr(x, "x", n);
            printArr(y, "y1", n);
        }
        private bool methodOfChordsCriterion(double x1, double x2, double e, function f, function fder1)
        {
            double c = Math.Abs(fder1(x1));

            ResultBox.Text += "Criterion: |f(x(n+1))| = " + Math.Abs(f(x2)) + "; alpha * epsilon = " + c * e + "\r\n";
            return(Math.Abs(f(x2)) < c * e);
        }
Example #5
0
        static void Main(string[] args)
        {
            Information();
            string readInput = "";

            while (readInput != "quit")
            {
                readInput = Console.ReadLine();
                function func = (function)System.Enum.Parse(typeof(function), readInput);
                switch (func)
                {
                case function.User:
                    UserFunction();
                    break;

                case function.Quit:
                    quitFunction();
                    break;

                default:
                    defaultFunction();
                    break;
                }
            }
        }
        private double GetFourierValue(function f, derivative2 d2, double min, double max, double val, int it)
        {
            it++;
            if (it > maxIterations)
            {
                //Console.WriteLine("Obtener Fourier Value: Mas de 30 iteraciones");
                return(GetValueInFourierInterval(f, d2, min, max, val));
            }
            double gMin   = f(min) - val;
            double gMax   = f(max) - val;
            double inter  = min + (max - min) / 2.0;
            double gInter = f(inter) - val;

            if (Math.Abs(gInter) < 0.02)
            {
                return(inter);
            }
            if (gMin * gInter < 0)
            {
                return(GetFourierValue(f, d2, min, inter, val, it));
            }
            else
            {
                return(GetFourierValue(f, d2, inter, max, val, it));
            }
        }
Example #7
0
        private static void num_du_rungekutt(function f, function g,
                                             double x0, double y0, int iColumn2Write,
                                             ref Matrix.Matrix Matr)
        {
            double t = 0, x1 = x0, y1 = y0;
            int    j = 0;
            double k1, k2, k3, k4, m1, m2, m3, m4;

            for (int i = 1; i <= 500; i++)             // max 5
            {
                t += h_rungekutt;
                k1 = f(t, x1, y1);
                m1 = g(t, x1, y1);
                k2 = f(t + h_rungekutt / 2, x1 + h_rungekutt * k1 / 2, y1 + h_rungekutt * m1 / 2);
                m2 = g(t + h_rungekutt / 2, x1 + h_rungekutt * k1 / 2, y1 + h_rungekutt * m1 / 2);
                k3 = f(t + h_rungekutt / 2, x1 + h_rungekutt * k2 / 2, y1 + h_rungekutt * m2 / 2);
                m3 = g(t + h_rungekutt / 2, x1 + h_rungekutt * k2 / 2, y1 + h_rungekutt * m2 / 2);
                k4 = f(t + h_rungekutt, x1 + h_rungekutt * k3, y1 + h_rungekutt * m3);
                m4 = g(t + h_rungekutt, x1 + h_rungekutt * k3, y1 + h_rungekutt * m3);
                x1 = x1 + h_rungekutt * (k1 + 2 * k2 + 2 * k3 + k4) / 6;
                y1 = y1 + h_rungekutt * (m1 + 2 * m2 + 2 * m3 + m4) / 6;

                if ((i == 100) || (i == 200) || (i == 300) || (i == 400) ||
                    (i == 500) || (i == 600) || (i == 700) ||
                    (i == 800) || (i == 900) || (i == 1000))                // 5
                {
                    Matr[j++, iColumn2Write] = x1 + y1;                     // 2.3
                }
            }
        }
        /** Method:  Try steffensen acceleration (if error, return -1)
         * f -  function
         * x - independent variable
         * min - min value of the interval
         * max -  max value of the interval
         * val -  value to add (0 if pure root search)
         * iterations - number of iterations */
        internal double TrySteffensenAcceleration(function f, derivative d, double x, double val, double iterations)
        {
            double gx     = f(x) - val;
            int    i      = 0;
            double xi     = -1;
            double xiMin1 = -1;
            double xiMin2 = -1;

            while (Math.Abs(gx) > epsilon)
            {
                if (d(x) == 0)
                {
                    return(0);
                }
                if (i < 4 || i % 2 == 0 || xi - 2 * xiMin1 + xiMin2 == 0)
                {
                    x = x - gx / d(x);
                }
                else
                {
                    x = GetAitkenIteration(xiMin2, xiMin1, xi);
                }
                gx     = f(x) - val;
                xiMin2 = xiMin1;
                xiMin1 = xi;
                xi     = x;
                i++;
                if (i > maxIterations)
                {
                    throw new Exception("Exceed maximun iterations");
                }
            }
            iterations = i;
            return(x);
        }
 public FunctionCallExpression(String functionName, List<Expression> args)
 {
     if (!functions.ContainsKey(functionName))
         throw new ArgumentException("Unknown function " + functionName);
     func = functions[functionName];
     arguments = args;
 }
Example #10
0
        public void MakeList(MyList list)
        {
            function f = list.Push;

            Operation(_root, f);
            Console.WriteLine("\n\n");
        }
        // Метод Хойна
        private void performTheHeunMethod(double a, double b, function func, int n, double x0, double y0)
        {
            double length = b - a;
            double h      = length / n;

            textBoxResultH.Text += "h = " + h + "\r\n";
            int roundNumber = 8;

            h = h.Truncate(roundNumber) + Math.Pow(10, -roundNumber);
            textBoxResultH.Text += "h = " + h + "\r\n";

            n = n + 1;

            double[] y = new double[n + 1];
            y[0] = y0;
            double[] x = new double[n + 1];
            x[0] = x0;

            double y1 = y[0];
            double yd = y[0];

            for (int i = 0; i < n; i++)
            {
                double innerFunction = func(x[i], y1);
                y1       = yd + (h / 2) * (func(x[i], y1) + func(x[i] + h, y1 + h * innerFunction));
                y[i]     = yd;
                yd       = y1;
                x[i + 1] = x[i] + h;
            }

            printArr(y, "y4", n);
        }
Example #12
0
        //Composite Simpson's Rule
        public static double Simpson(double a, double b, function f, int n)
        {
            double approx;
            double h = (b - a) / (2 * n);
            double[] values = new double[2*n + 1];
            int i = 0;
            double evenSum = 0;
            double oddsum = 0;

            values[0] = a;
            values[2*n] = b;

            for(i = 1; i < n; i++)
            {
                values[2*i] += a + (2*i*h);
                evenSum += f(values[2 * i]);
            }

            for (i = 1; i <= n; i++ )
            {
                values[(2 * i) - 1] += a + (((2 * i) - 1) * h);
                oddsum += f(values[(2 * i) - 1]);
            }

            approx = (h / 3) * (f(a) + f(b) + 4 * oddsum + 2 * evenSum);

            return approx;
        }
 public RichardsonExtrapolation( function f, double delta_h, double? n = null )
 {
    delta_h_ = delta_h;
    fdelta_h_ = f(delta_h);
    n_ = n;
    f_ = f;
 }
Example #14
0
 public WindowForm(action callbackA, function callbackF)
 {
     InitializeComponent();
     callbackAction   = callbackA;
     callbackFunction = callbackF;
     handler         += changeLabel;
 }
Example #15
0
        private static void Shuffle(int[] data)
        {
            Random random = new Random();

            function swap = (values, pos1, pos2) =>
            {
                int temp = values[pos1];
                values[pos1] = values[pos2];
                values[pos2] = temp;
            };

            Int32[] array = new int[16];

            for (int i = 0; i < 16; i++)
            {
                array[i] = random.Next(int.MaxValue);
            }

            for (int i = 0; i < data.Length; ++i)
            {
                for (int j = 0; j < data.Length - i - 1; j++)
                {
                    if (array[j].CompareTo(array[j + 1]) > 0)
                    {
                        swap(array, j, j + 1);
                        swap(data, j, j + 1);
                    }
                }
            }
        }
Example #16
0
        public void MakeAList(MyList some_list)
        {
            function f = some_list.Push;

            DoSomethingWithNodes(_root, f);
            Console.WriteLine("\n\n");
        }
Example #17
0
        static void methodDyhotomii(double x1, double x2, double E, function f)
        {
            Console.WriteLine("\t== Метод дихотомiї ==\n");
            int    i     = 0;
            double x     = x1;
            double xLast = x;
            double xTo   = x2;
            double dx    = double.MaxValue;

            while (Math.Abs(dx) > 2 * E)
            {
                i++;
                x = (xTo + xLast) / 2;
                if (f(xTo) * f(x) < 0)
                {
                    xLast = x;
                }
                else if (f(xTo) * f(x) == 0)
                {
                    break;
                }
                else
                {
                    xTo = x;
                }
                dx = xTo - xLast;
            }

            Console.WriteLine($" x = {Math.Round(x, 3)}");
            Console.WriteLine($" Кiлькiсть iтерацiй = {i}\n");
        }
        private double methodOfSimpleIterations(double a, double b, double e, function f, function fder1)
        {
            if (a > b)
            {
                double c = a;
                a = b;
                b = c;
            }
            double j1     = fder1(a);
            double j2     = fder1(b);
            double lambda = 2 / (j1 + j2);
            double q      = (j2 - j1) / (j2 + j1);

            ResultBox.AppendText("alpha = " + j1 + "; gamma = " + j2 + "; lambda = " + lambda + "; q = " + q + "\r\n");

            double xn1 = a, xn2;
            int    n = 1;

            while (true)
            {
                xn2 = xn1 - lambda * f(xn1);
                ResultBox.AppendText(n.ToString() + " iteration. Root: " + xn2.ToString() + "\r\n");
                if (Math.Abs(xn2 - xn1) <= ((1 - q) / q) * e)
                {
                    return(xn2);
                }
                n++;
                if (n > 2000)
                {
                    ResultBox.AppendText("The iteration number became more than 2000. Overflow!\r\nAborting...\r\n");
                    return(xn2);
                }
                xn1 = xn2;
            }
        }
        private int SetAllValuesBisection(Dictionary <int, double> values, function f, double min, double max, double fmin, double fmax)
        {
            int it  = 0;
            int its = 0;

            if (max - min <= 0.1)
            {
                values[GetKey(min)] = fmin;
                values[GetKey(max)] = fmax;
            }
            else if (fmax - fmin < 1)
            {
                for (int i = GetKey(min); i <= GetKey(max); i++)
                {
                    values[i] = fmax;
                }
            }
            else
            {
                double fmid = (fmin + fmax) / 2.0;
                double mid  = Math.Round(f(fmid) * 100, 1);
                if (mid <= min || mid >= max)
                {
                    mid  = (min + max) / 2.0;
                    fmid = MonotoneBisection(f, true, fmin, fmax, mid / 100.0, 0.001, ref it, 100);
                    its += it;
                }
                its += SetAllValuesBisection(values, f, min, mid, fmin, fmid);
                its += SetAllValuesBisection(values, f, mid, max, fmid, fmax);
            }
            return(its);
        }
Example #20
0
        private void dataGridView1_Click(object sender, EventArgs e)
        {
            int rowIndex = dataGridView1.CurrentCell.RowIndex;
            int Collumn  = dataGridView1.CurrentCell.ColumnIndex;

            string MonHoc = dataGridView1.Rows[rowIndex].Cells[Collumn].Value.ToString();

            if (MonHoc == "Trống")
            {
                return;
            }

            TimeSpan sp = new TimeSpan(Collumn - 1, 0, 0, 0, 0);

            dateTimePicker1.Value = LayMonday(dateTimePicker1.Value) + sp;
            DataTable LichHoc = new function().LayLichHoc_Ngay(Ma_HocSinh, dateTimePicker1.Value);

            foreach (DataRow row in LichHoc.Rows)
            {
                if (row["KipHoc"].ToString() == (rowIndex + 1).ToString())
                {
                    txbMa_LopHoc.Text    = row["Ma_LopHoc"].ToString();
                    txbMa_BuoiHoc.Text   = row["Ma_BuoiHoc"].ToString();
                    txbPhongHoc.Text     = row["PhongHoc"].ToString();
                    txbTen_GiaoVien.Text = row["Ten_GiaoVien"].ToString();
                    Ma_LopHoc            = txbMa_LopHoc.Text;
                }
            }
        }
        /** Method:
         * Devuelve el punto de fourier con el que el metodo de Newton Raphson converge muy rapidamente
         * Fourier Convergence Conditions value. Returns zero if does not fit conditions
         * f(a)*f(b) less than 0   2) f" greater than 0 en [a,b]  val is for non roots (otherwise 0)
         * f - funcion mediante la cual se calcula el valor de dicha funcion
         * d2 - funcion mediante la cual se calcula el valor de la derivada segunda de dicha funcion
         * a - Valor minimo del intervalo en el cual busca la raiz o cero
         * b - Valor maximo del intervalo en el cual busca la raiz o cero
         * val - Valor para el cual se desea buscar la inversa de la función */
        private double GetValueInFourierInterval(function f, derivative2 d2, double a, double b, double val)
        {
            double posValue = 0;
            double negValue = 0;
            double ga       = f(a) - val;
            double gb       = f(b) - val;

            if (ga * gb >= 0)
            {
                return(0);
            }
            if (ga > 0)
            {
                posValue = a; negValue = b;
            }
            else
            {
                posValue = b; negValue = a;
            }

            //Second derivative constant in the interval (warning: sign is not verified on intermediate values)
            if (d2(a) > 0 && d2(b) > 0)
            {
                return(posValue);
            }
            else
            {
                return(negValue);
            }
        }
Example #22
0
 public void walk_in(function callback, bool neurons = false, bool inputs = true)
 {
     for (int layer = this.layers_count - 1; layer >= 0; layer--)
     {
         if (!neurons && !inputs)
         {
             callback(layer, -1, -1);
         }
         if (neurons || inputs)
         {
             for (int neuron = 0; neuron < this.Layer[layer].neurons_count; neuron++)
             {
                 if (neurons)
                 {
                     callback(layer, neuron, -1);
                 }
                 if (inputs)
                 {
                     for (int input = 0; input < this.neuron(layer, neuron).inputs_count; input++)
                     {
                         callback(layer, neuron, input);
                     }
                 }
             }
         }
     }
 }
Example #23
0
 public RichardsonExtrapolation(function f, double delta_h, double?n = null)
 {
     delta_h_  = delta_h;
     fdelta_h_ = f(delta_h);
     n_        = n;
     f_        = f;
 }
Example #24
0
        static void methodNewton(double x1, double x2, double E, function functionTask, function derivativeFunction, function secondDerivativeFunction, String equation)
        {
            Console.WriteLine("\t== Метод Ньютона (дотичних) ==\n");
            int    iterator = 1;
            double initValueX;
            double iValueX;
            double a = x1;
            double b = x2;
            double e = E;

            if (functionTask(a) * functionTask(b) > 0) // Якщо знаки функції на краях відрізків однакові, то функція коренів немає
            {
                Console.WriteLine("На даному iнтервалi [{0};{1}] рiвняння {2} немає розв'язкiв", a, b, equation);
            }
            else
            {
                initValueX = functionTask(a) * secondDerivativeFunction(a) > 0 ? a : b;              // Визначаємо нерухомий кінець та задаємо початкове значення
                iValueX    = initValueX - functionTask(initValueX) / derivativeFunction(initValueX); // Визначаємо перше наближення
                Console.WriteLine("Поточна iтерацiя {0} = {1}", iterator, iValueX);
                while (Math.Abs(initValueX - iValueX) > e)                                           // Поки різниця по модулю між коренями не стане меншою за точність e
                {
                    iterator++;
                    initValueX = iValueX;
                    iValueX    = initValueX - functionTask(initValueX) / derivativeFunction(initValueX);
                    Console.WriteLine("Поточна iтерацiя {0} = {1}", iterator, iValueX);
                }
                Console.WriteLine($" x = {Math.Round(iValueX, 3)}");
                Console.WriteLine($" Кiлькiсть iтерацiй = {iterator}\n");
            }
        }
Example #25
0
        public void PrintElements()
        {
            Console.WriteLine("\n\nelements of the tree are\n\n");
            function f = PrintInfo;

            Operation(_root, f);
            Console.WriteLine("\n");
        }
Example #26
0
        public void PrintElements()
        {
            Console.WriteLine("\n\nelements of the tree are\n\n");
            function f = PrintNodeInfo;

            DoSomethingWithNodes(_root, f);
            Console.WriteLine("\n");
        }
Example #27
0
    public static void Play(function f)
    {
        float time = Time.realtimeSinceStartup;

        f();

        Debug.Log(f.Method.Name + " cost: " + (Time.realtimeSinceStartup - time).ToString("F3") + "s");
    }
 // Someone tell me if there's a better way to document three similar but slightly different methods...
 /// <summary>
 /// A TFunction constructor.
 /// </summary>
 /// <param name="name">The name of the new Toast function.</param>
 /// <param name="function">The C# method which is called when the Toast function is called.</param>
 /// <param name="argNames">
 /// The argument names to use in the function. Pass null for the function to use a variable number of
 /// arguments.
 /// </param>
 /// <param name="defaultArgs">
 /// The default values of arguments, as TTypes. Use null in the array to specify that no default value should
 /// be used for a particular argument, or pass null to indicate that no arguments should have default values.
 /// </param>
 public TFunction(string name, function function, string[] argNames, TType[] defaultArgs)
 {
     Name = name;
     HardCodedFunction = function;
     CustomFunction = "";
     Block = null;
     CopyArguments(argNames, defaultArgs);
 }
        public static double diff_3(function f, Coord x, int number)
        {
            double dx     = 1e-7;
            int    length = x.coord.Length;
            Coord  x_dx   = dx * Coord.Ort(length, number);

            return((f(x - x_dx) - 4 * f(x) + 3 * f(x + x_dx)) / (2 * dx));
        }
        public static double diff_4(function f, Coord x, int number)
        {
            double dx     = 1e-7;
            int    length = x.coord.Length;
            Coord  x_dx   = dx * Coord.Ort(length, number);

            return((-f(x + 2 * x_dx) + 8 * f(x + x_dx) - 8 * f(x - x_dx) + f(x - 2 * x_dx)) / (12 * dx));
        }
Example #31
0
        // Someone tell me if there's a better way to document three similar but slightly different methods...

        /// <summary>
        /// A TFunction constructor.
        /// </summary>
        /// <param name="name">The name of the new Toast function.</param>
        /// <param name="function">The C# method which is called when the Toast function is called.</param>
        /// <param name="argNames">
        /// The argument names to use in the function. Pass null for the function to use a variable number of
        /// arguments.
        /// </param>
        /// <param name="defaultArgs">
        /// The default values of arguments, as TTypes. Use null in the array to specify that no default value should
        /// be used for a particular argument, or pass null to indicate that no arguments should have default values.
        /// </param>
        public TFunction(string name, function function, string[] argNames, TType[] defaultArgs)
        {
            Name = name;
            HardCodedFunction = function;
            CustomFunction    = "";
            Block             = null;
            CopyArguments(argNames, defaultArgs);
        }
Example #32
0
        private double rectangleTrapeziumAlgorithm(double b, double a, function func, double epsilon)
        {
            int maxArrSize = 30; // this is my value for an array max size

            int    n   = 1;
            double H   = b - a;
            double ItH = (H / 2) * (func(b) + func(a)); // I^T(H)

            double Ich;                                 // result

            double[,] resultArr = new double[maxArrSize, 4];
            resultArr[0, 0]     = ItH;
            // there will be more elements for this array:
            // resultArr[0, 1] = IpH;
            // resultArr[0, 2] = Ith;
            // resultArr[0, 3] = Rth;

            int j = 0; // the 'while' count

            while (true)
            {
                double h = H / 2;
                double x = a + h;
                double y;
                double sum = 0;
                for (int i = 1; i <= n; i++)
                {
                    if (i != 1)
                    {
                        x = x + H;
                    }
                    y    = func(x);
                    sum += y;
                }
                double IpH = resultArr[j, 1] = sum * H;           // I^P(H)

                double Ith = resultArr[j, 2] = 0.5 * (IpH + ItH); // I^T(h)
                double dif = Ith - ItH;
                double Rth = resultArr[j, 3] = dif / 3;           // R^T(h)

                Rth = Math.Abs(Rth);
                if (Rth > epsilon)
                {
                    n = 2 * n;
                    H = h;
                    resultArr[j + 1, 0] = ItH = Ith;
                }
                else
                {
                    Ich = Ith + Rth;
                    break;
                }
                j++;
            }
            printTheResultTable(resultArr, j + 1);
            textBoxResult.Text += "Result (I^C(h)): " + Ich + "\r\n";
            return(Ich);
        }
        public object Insert(List <FileModel> files, function item, Function_Extend itemExtend)
        {
            Message msg = new Message {
                Error = false
            };

            using (DbContextTransaction dbTran = _dbContext.Database.BeginTransaction())
            {
                try
                {
                    if (getNotExistsFunctionWhenInsert(item.Function1))
                    {
                        item.CreatedBy    = ((account)Session["informationOfAccount"]).Account1;
                        item.CreatedDate  = DateTime.Now;
                        item.ModifiedBy   = ((account)Session["informationOfAccount"]).Account1;
                        item.ModifiedDate = DateTime.Now;
                        if (item.functionCategories != null)
                        {
                            item.functionCategoriesTitle = _dbContext.functionCategories.First(x => x.functionCategories == item.functionCategories).functionCategoriesTitle;
                        }
                        _dbContext.functions.Add(item);
                        _dbContext.SaveChanges();
                        msg.Title = Function_Message_InsertSuccess;
                        var ChildFunction = _dbContext.childOfFunctions.ToList();
                        foreach (var itemChild in ChildFunction)
                        {
                            if (itemExtend.ArrayFunction != null)
                            {
                                if (itemExtend.ArrayFunction.Find(x => x == itemChild.ChildOfFunction1) == null)
                                {
                                    itemChild.RemoveFunction += "#" + itemExtend.Function1 + "#";
                                    _dbContext.Entry(itemChild).Property(x => x.ID).IsModified    = false;
                                    _dbContext.Entry(itemChild).Property(x => x.Title).IsModified = false;
                                    _dbContext.Entry(itemChild).Property(x => x.Order).IsModified = false;
                                    _dbContext.SaveChanges();
                                }
                            }
                        }
                        dbTran.Commit();
                    }
                    else
                    {
                        msg.Title = Function_Message_InsertErrror;
                        msg.Error = true;
                        dbTran.Rollback();
                    }
                }
                catch (Exception ex)
                {
                    msg.Title = Function_Message_InsertErrror;
                    msg.Error = true;
                    msg.Data  = ex.ToString();
                    dbTran.Rollback();
                }
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
Example #34
0
        void Load()
        {
            EC_HocSinh HocSinh = new BUS_HocSinh().Select_ByPrimaryKey(Ma_HocSinh);

            if (HocSinh.Anh != null)
            {
                picAvt.Image = HinhAnh.ByteToImage(HocSinh.Anh);
            }
            txbMa_HocSinh.Text      = HocSinh.Ma_HocSinh;
            txbTen_HocSinh.Text     = HocSinh.Ten_HocSinh;
            txbDiaChi.Text          = HocSinh.DiaChi;
            txbEmail.Text           = HocSinh.Email;
            txbSDT.Text             = HocSinh.SDT;
            dtNgaySinh.Value        = HocSinh.NgaySinh;
            cbGioiTinh.SelectedItem = HocSinh.GioiTinh == true ? "Nam" : "Nữ";
            cbLop.SelectedItem      = HocSinh.Lop.ToString();

            function  ft             = new function();
            DataTable LopHoc_DangHoc = ft.LopHoc_DangHoc(Ma_HocSinh);
            DataTable LopHoc_DaHoc   = ft.LopHoc_DaHoc(Ma_HocSinh);
            int       index1         = 1;

            foreach (DataRow row in LopHoc_DangHoc.Rows)
            {
                string    Ma_LopHoc = row[0].ToString();
                EC_LopHoc LopHoc    = new BUS_LopHoc().Select_ByPrimaryKey(Ma_LopHoc);
                EC_MonHoc MonHoc    = new BUS_MonHoc().Select_ByPrimaryKey(LopHoc.Ma_MonHoc);
                dgLopHoc.Rows.Add(index1.ToString(), Ma_LopHoc, MonHoc.Ten_MonHoc, MonHoc.Lop, LopHoc.SoBuoi, "Đang học");
                index1++;
            }
            foreach (DataRow row in LopHoc_DaHoc.Rows)
            {
                string    Ma_LopHoc = row[0].ToString();
                EC_LopHoc LopHoc    = new BUS_LopHoc().Select_ByPrimaryKey(Ma_LopHoc);
                EC_MonHoc MonHoc    = new BUS_MonHoc().Select_ByPrimaryKey(LopHoc.Ma_MonHoc);
                dgLopHoc.Rows.Add(index1.ToString(), Ma_LopHoc, MonHoc.Ten_MonHoc, MonHoc.Lop, LopHoc.SoBuoi, "Đã học");
                index1++;
            }

            DataTable HocPhi_Thang = ft.TongTien_Thang(Ma_HocSinh);

            dgHocPhi.Rows.Clear();
            foreach (DataRow row in HocPhi_Thang.Rows)
            {
                string ChuaDong          = row["TongTien_ChuaDong"].ToString();
                int    TongTien_ChuaDong = 0;
                if (ChuaDong == "" || ChuaDong == null)
                {
                    TongTien_ChuaDong = 0;
                }
                else
                {
                    TongTien_ChuaDong = (int)row["TongTien_ChuaDong"];
                }
                dgHocPhi.Rows.Add(row["Thang"].ToString() + "/" + row["Nam"].ToString(), row["TongTien"].ToString(), (int)row["TongTien"] - TongTien_ChuaDong, TongTien_ChuaDong);
            }
        }
        public static double second_diff_2(function f, Coord x, int number_1, int number_2)
        {
            double dx     = 1e-5;
            int    length = x.coord.Length;
            Coord  x_dx_1 = dx * Coord.Ort(length, number_1);
            Coord  x_dx_2 = dx * Coord.Ort(length, number_2);

            return((f(x + x_dx_1 + x_dx_2) - f(x + x_dx_1 - x_dx_2) - f(x - x_dx_1 + x_dx_2) + f(x - x_dx_1 - x_dx_2)) / (4 * dx * dx));
        }
 public FunctionCallExpression(String expr)
 {
     expr = expr.Substring(1, expr.Length - 2);
     string[] split = splitArgs(expr);
     if (!functions.ContainsKey(split[0]))
         throw new ArgumentException("Unknown function " + split[0]);
     func = functions[split[0]];
     arguments = new List<Expression>();
     for (int i = 1; i < split.Length; i++)
         arguments.Add(Expression.fromString(split[i]));
 }
Example #37
0
 public Register()
 {
     _name = "imma regista";
     _address = 1;
     _valueType = valueType.UINT16;
     _commandFunction = function.Holding;
     _pureValue = "0";
     _value = "0";
     _timeStamp = DateTime.Now;
     _quality = quality.Unknown;
     _val = new Value();
 }
Example #38
0
 public static void remove(String type, function call)
 {
     List<function> funcs = observers[type];
     if (funcs != null)
     {
         int index = funcs.IndexOf(call);
         if (index != -1)
         {
             funcs.RemoveAt(index);
         }
     }
 }
Example #39
0
 public void removeEventListener(string type,function listener)
 {
     List<function> funcs = observers[type];
     if (funcs != null)
     {
         int index = funcs.IndexOf(listener);
         if (index != -1)
         {
             funcs.RemoveAt(index);
         }
     }
 }
Example #40
0
        //Newtons Method Algorithm
        public static double Algorithm(function f, function fp, int nmax, double tol, double xzero)
        {
            double xone = 0.0;

            for (int n = 0; (Math.Abs(xzero - xone)) > tol || n < nmax; n++)
            {
                if (f(xzero) != 0.0 && fp(xzero) != 0.0)
                {
                    xzero = xzero - f(xzero) / fp(xzero);
                    xone = xzero;
                }
            }

            return xzero;
        }
Example #41
0
 public void addEventListener(string type,function listener)
 {
     List<function> funcs;
     if (observers.ContainsKey(type) == false)
     {
         funcs = new List<function>();
         observers[type] = funcs;
     }
     else
     {
         funcs = observers[type];
     }
     if (funcs.IndexOf(listener) == -1)
     {
         funcs.Add(listener);
     }
 }
Example #42
0
        public static void register(String type, function call, String module = null, String method = null)
        {
            List<function> funcs;
            //mapping[function] = {"module": module, "method": method};

            if (observers.ContainsKey(type) == false)
            {
                funcs = new List<function>();
                observers[type] = funcs;
            }
            else
            {
                funcs = observers[type];
            }
            if (funcs.IndexOf(call) == -1)
            {
                funcs.Add(call);
            }
        }
Example #43
0
        public Bj_structure_original(string bj_orgPath)
        {
            string line;
            StreamReader bj_org = new StreamReader(bj_orgPath);
            while ((line = bj_org.ReadLine()) != null)
            {

                //===========读取声明===========
                if (line.Trim() == "globals")
                {
                    int i = 0;
                    while ((line = bj_org.ReadLine()) != "endglobals")
                    {
                        string temps = line.Trim();
                        if (temps.Length != 0 && temps.IndexOf("//") != 0)
                        {
                            this.Global_org.Add(line);
                            i++;
                        }
                    }
                    this.GlobalCount_org = i;
                }
                //===========读取函数===========
                if (line.IndexOf("function") == 0)
                {
                    this.FunctionCount_org++;

                    function f = new function();
                    f.name = line.Substring(8, line.IndexOf(" takes") - 8);
                    f.content = f.content + (line + System.Environment.NewLine);
                    while ((line = bj_org.ReadLine()) != "endfunction")
                    {
                        f.content = f.content + (line + System.Environment.NewLine);
                    }
                    f.content = f.content + (line + System.Environment.NewLine);

                    this.Function_org.Add(f);
                }

            }
            bj_org.Close();
        }
Example #44
0
        public static void RungeKutta(function f, double a, double b, double h, double initial)
        {
            int size = Convert.ToInt32(b / h);
            double[] y = new double[size + 1];
            double[] t = new double[size + 1];
            double[] k = new double[4];

            y[0] = initial;
            t[0] = a;

            for(int i = 0; t[i] != b; i++)
            {
                t[i + 1] = t[i] + h;
                k[0] = f(t[i], y[i]);
                k[1] = f((t[i] + (h/2)), (y[i] + ((h/2) * k[0])));
                k[2] = f((t[i] + (h / 2)), (y[i] + ((h/2) * k[1])));
                k[3] = f((t[i] + h), (y[i] + (h * k[2])));
                y[i + 1] = y[i] + (h / 6) * (k[0] + 2*k[1] + 2*k[2] + k[3]);
                Console.WriteLine("y(" + t[i + 1] + ") = " + y[i + 1]);
            }
        }
Example #45
0
        // функция рисует график заданной функции function
        private void DrawGraph(Graphics ln, function f, Color color)
        {
            Point p1, p2;
            int Xpoint = 0, Ypoint = 0;
            int height = pictureBox.Height; // Высота
            int width = pictureBox.Width;   // Ширина
            string str;
            bool flag = true;

            for (double x = -10; x < 10; x += 0.06)
            {
                x = Math.Round(x, 1);
                str = f(x).ToString();
                if (str != "бесконечность" && str != "NaN" && str != "-бесконечность")
                {
                    if (flag)
                    {
                        double h = Math.Round(f(x));
                        int g = (int)(h);
                        Ypoint = (height / 2 - g * ScaleValue);
                        h = Math.Round(x);
                        g = (int)(h);
                        Xpoint = (width / 2 + g * ScaleValue);
                        flag = false;
                    }
                    p1 = new Point(Xpoint, Ypoint);
                    double y = -f(x);
                    Xpoint = (int)(x * ScaleValue + width / 2);
                    Ypoint = (int)(y * ScaleValue + height / 2);
                    p2 = new Point(Xpoint, Ypoint);
                    Pen pen = new Pen(color, 1);
                    ln.DrawLine(pen, p1, p2);
                }
                else flag = true;
            }
        }
Example #46
0
        //Composite Midpoint Rule
        public static double Midpoint(double a, double b, function f, int n)
        {
            double approx = 0;
            double h = (b - a) / n;
            double[] values = new double[n + 1];
            double[] wValues = new double[n + 1];
            double sum = 0;
            int i = 0;

            for(i = 0; i <= n; i++)
            {
                values[i] = f(a + i*h);
            }

            for(i = 1; i <= n; i++)
            {
                wValues[i] = (values[i] + values[i-1]) / 2;
                sum += wValues[i];
            }

            approx = h*sum;

            return approx;
        }
Example #47
0
			/**
			 * Associates a menu item with a function
			 */
			void AddOption(string option, function func);
Example #48
0
		/**
		 * Creates a named timer that will be added to the timers list. If a named timer already exists,
		 * it will be replaced.
		 *
		 * @return Name of the created timer
		 */
		string AddTimerByName(string strName, double delay, bool repeat, function func, object[] paramTable = null, int flags = 0);
Example #49
0
 public void Read(function function)
 {
     // OpenPort
     _registers = new List<Register>();
 }
Example #50
0
    void Awake()
    {
        trashPrompt = "        YES, TRASH IT\n         NO, KEEP IT";
        GameObject global = GameObject.FindGameObjectWithTag ("GameController");
        inventory = global.GetComponent<Inventory>();
        data = global.GetComponent<GameData>();

        if (inventory == null || selector == null || data == null)
            Debug.LogError("KeyComponent of the display is null!");

        //ALSO SWAP OUT ITEMS HERE
        slots = inventory.itemsList;
        keySlots = inventory.keyItemsList;

        pushCounter = pushWaitTime;
        selectedPlayer = player.ANNIE;
        currentState = state.SELECT_STATE;
        currentFunction = function.USE;
    }
Example #51
0
		/**
		 * Adds to the entity's THINK function. You can use "this.ent" when you need to use the VSLib::Entity.
		 * 
		 * @param func A function to add to the think timer.
		 */
		void AddThinkFunction( function func );
Example #52
0
			/**
			 * Starts the countdown from the specified time
			 */
			void Start(function func, int hours = 0, int minutes = 0, int seconds = 0);
Example #53
0
 public void Write(function function, List<Register> registersToWrite)
 {
 }
Example #54
0
 public abstract void SetFunc(function f);
Example #55
0
		/**
		 * Calls a function and passes the specified table to the callback after the specified delay.
		 * Returns the current timer index (which you can use to delete the timer later with Timers::RemoveTimer function).
		 */
		int AddTimer(double delay, bool repeat, function func, object[] paramTable = null, int flags = 0, object[] value = {});
Example #56
0
    void selectState()
    {
        stateSelector.active = true;
        playerSelector.active = false;
        selector.active = false;

        if (Input.GetButtonDown ("Confirm")) { //Charge is basically the A button
            if(currentFunction == function.USE || currentFunction == function.DELETE) {
                currentState = state.SELECT_ITEM;
                makeSound(confirm);
            }
            else if(currentFunction == function.SWAP) {
                currentState = state.SELECT_ITEM;
                makeSound(confirm);
            }
        }
        else if(Input.GetButtonDown("Deny")) { //Basically the "B" button
            manager.closeMenu();
        }
        else if (vert == -1) {
            pushCounter++;
            if(pushCounter>=pushWaitTime) {
                Vector3 pos = stateSelector.localPosition;
                makeSound(selectNoise);
                pushCounter = 0;
                if(currentFunction == function.USE) {
                    pos.y = -8.3f;
                    currentFunction = function.SWAP;
                }
                else if(currentFunction == function.SWAP) {
                    if(deleteState != null) {
                        pos.y = -16.7f;
                        currentFunction = function.DELETE;
                    }
                    else {
                        pos.y = 0;
                        currentFunction = function.USE;
                    }
                }
                else if (currentFunction == function.DELETE) {
                    pos.y = 0;
                    currentFunction = function.USE;
                }
                stateSelector.localPosition = pos;
            }
        }
        else if (vert == 1) {
            pushCounter++;
            if(pushCounter>=pushWaitTime) {
                Vector3 pos = stateSelector.localPosition;
                makeSound(selectNoise);
                pushCounter = 0;

                if(currentFunction == function.USE) {
                    if(deleteState != null) {
                        pos.y = -16.7f;
                        currentFunction = function.DELETE;
                    }
                    else {
                        pos.y = -8.3f;
                        currentFunction = function.SWAP;
                    }
                }
                else if(currentFunction == function.SWAP) {
                    pos.y = 0;
                    currentFunction = function.USE;
                }
                else if (currentFunction == function.DELETE) {
                    pos.y = -8.3f;
                    currentFunction = function.SWAP;
                }
                stateSelector.localPosition = pos;
            }
        }
        else pushCounter = pushWaitTime;
    }
Example #57
0
 public static int setTimeout(function fun, int delay, object[] args = null)
 {
     if (delay == 0) {
             fun(args);
             return 0;
         }
         delayIDKey++;
         Dictionary<string, object> dict = new Dictionary<string, object>();
         dict["key"] = delayIDKey;
         dict["startTime"] = Time.time;
         dict["count"] = delay;
         dict["handler"] = fun;
         dict["arg"] = args;
         if (timeoutDic.ContainsKey(delayIDKey) == false)
         {
             timeoutDic[delayIDKey] = dict;
         }
         return delayIDKey;
 }
 //Cette classe à été créée pour ne pas être une fonction de la classe UserInterface
 //Elle est utilisée pour lancer dans un thread une fonction qui ajoutera
 //des mouvements à la pile, on lui passera donc en paramètre des nom de fonction
 //de dessin, présentes dans UserInterface
 //Le lancement d'une fonction de dessin dans un thread est faite
 //pour pouvoir :  bloquer l'ajout de points, ou encore éviter de "geler"
 //la fenêtre
 public runInThread(function f)
 {
     this.funcThread = new Thread(new ThreadStart(f));
     this.funcThread.Priority = ThreadPriority.Normal;
     this.funcThread.Start();
 }
Example #59
0
		/**
		 * Connects an output to a function
		 *
		 * @param output The output name (string)
		 * @param func Function to fire (pass in a function, not a string name)
		 */
		void ConnectOutput( string output, function func );
Example #60
0
        public function functionToExec = null; // the function to execute when the time to execute it comes.

        #endregion Fields

        #region Constructors

        // Constructor with defaults to be assigned.
        public ScheduledFunction( float time, function fn )
        {
            delay = time;
            functionToExec = fn;
        }