示例#1
0
        public void General(double from, double to, uint divisions, Enum enumFunc)
        {
            double step = Integral.GetStep(from, to, divisions);

            double[] FxArray = new double[divisions + 1];

            ConcurrentBag <Tuple <double, double> > bag = new ConcurrentBag <Tuple <double, double> >();

            int    j      = 0;
            double jcoord = 0;

            Func <double, double> func = Integral.Sinx;

            switch (enumFunc)
            {
            case EnumFunc.Sin:
                func = Integral.Sinx;
                break;

            case EnumFunc.Sqrt:
                func = Integral.Sqrtx;
                break;

            case EnumFunc.Sech:
                func = Integral.Sechx;
                break;
            }

            foreach (double i in Integral.GetFx(func, from, to, step))
            {
                this.Dispatcher.Invoke(() =>
                {
                    switch (enumFunc)
                    {
                    case EnumFunc.Sin:
                        mySinCanvas.Children.Clear();
                        sinCurve.Points.Add(new Point((jcoord * 40) + 50, (i * 40) - 150));
                        mySinCanvas.Children.Add(sinCurve);
                        break;

                    case EnumFunc.Sqrt:
                        mySqrtCanvas.Children.Clear();
                        sqrtCurve.Points.Add(new Point((jcoord * 40) + 50, (i * 40) - 150));
                        mySqrtCanvas.Children.Add(sqrtCurve);
                        break;

                    case EnumFunc.Sech:
                        mySechCanvas.Children.Clear();
                        sechCurve.Points.Add(new Point((jcoord * 40) + 50, (i * 40) - 150));
                        mySechCanvas.Children.Add(sechCurve);
                        break;
                    }
                    FxArray[j] = i;
                    j++;
                    jcoord += step;
                });
            }

            foreach (Tuple <double, double> i in Integral.GetFxPairs(FxArray))
            {
                bag.Add(i);
            }

            Task <double>[] tasks = new Task <double>[] {
                new Task <double>(() => FindArea(bag, step)),
                new Task <double>(() => FindArea(bag, step)),
                new Task <double>(() => FindArea(bag, step)),
            };

            double sum = 0;

            Array.ForEach(tasks, t => t.Start());
            Array.ForEach(tasks, t => sum += t.Result);
            Task.WaitAll(tasks);

            switch (enumFunc)
            {
            case EnumFunc.Sin:
                myDataContext.SinCorrectTill = sum.ToString();
                break;

            case EnumFunc.Sqrt:
                myDataContext.SqrtCorrectTill = sum.ToString();
                break;

            case EnumFunc.Sech:
                myDataContext.SechCorrectTill = sum.ToString();
                break;
            }
        }