Exemplo n.º 1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (GetInput(out double x0, out double y0, out double xN, out double accuracy, out string function))
            {
                double n    = (xN - x0 + 1) * 10;
                double step = (xN - x0) / n;

                double[]           y   = MilneCalculator.Calculate(Functions[function], x0, y0, step, n, accuracy, out double[] x);
                LagrangePolynomial pol = new LagrangePolynomial(x, y);

                if (Plot.Model.Series.Count != 0)
                {
                    Plot.Model.Series.Clear();
                }

                //Supposed option
                Plot.Model.Series.Add(new FunctionSeries(pol.Compute, x0, xN, step));

                //-------------------------------------------------------
                //Alternative option if something went wrong
                //-------------------------------------------------------
                //OxyPlot.Series.LineSeries lineSeries = new OxyPlot.Series.LineSeries();
                //for (int counter = 0; counter < y.Length; counter++)
                //{
                //    lineSeries.Points.Add(new DataPoint(x[counter], y[counter]));
                //}
                //Plot.Model.Series.Add(lineSeries);


                Plot.Model.InvalidatePlot(true);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var data     = GenerateArray(STUDENT_NUMBER, GROUP_NUMBER);
            var lagrange = LagrangePolynomial.Calculate(data[0], data[1]);

            Console.WriteLine("Points (x/y): ");
            var points_x = new VectorRow(data[0]);
            var points_y = new VectorRow(data[1]);

            points_x.Print();
            points_y.Print();
            Console.Write("L(x) = ");
            lagrange.Print();
            lagrange.FindDerivative().FindDerivative().Print();

            Console.WriteLine("\nCheck: ");
            for (int i = 0; i < data[0].Length; i++)
            {
                Console.WriteLine("L({0}) = {1}", data[0][i], lagrange.Calculate(data[0][i]));
            }
            Console.Read();
        }
        public IEnumerable <byte> Decompress(IEnumerable <byte> compressed)
        {
            var bits     = new BitArray(compressed.ToArray());
            var tmpArray = new int[bits.Count];

            bits.CopyTo(tmpArray, 0);
            decimal            encoded    = new decimal(tmpArray);
            var                mixedBytes = this.ArithmeticalCodec.Decompress(encoded, 6);
            var                yCounter   = mixedBytes.Count() / 6;
            IEnumerable <byte> Ys         = mixedBytes.Take(4 * yCounter).Select(x => (byte)(x + 128));
            IEnumerable <byte> Us         = this.DctTransformer.ConvertReversely(
                this.Quantizer.Dequantize(
                    this.RleCodec.Decompress(
                        mixedBytes.Skip(4 * yCounter).Take(yCounter)
                        )
                    )
                );
            IEnumerable <byte> Vs = this.DctTransformer.ConvertReversely(
                this.Quantizer.Dequantize(
                    this.RleCodec.Decompress(
                        mixedBytes.Skip(5 * yCounter).Take(yCounter)
                        )
                    )
                );

            var        indices            = Enumerable.Range(0, 64).Select(x => x * 4).ToList();
            var        VlagrangeTable     = indices.Zip(Vs, (x, y) => new { x, y }).ToDictionary(x => (double)x.x, x => (double)x.y);
            var        UlagrangeTable     = indices.Zip(Us, (x, y) => new { x, y }).ToDictionary(x => (double)x.x, x => (double)x.y);
            List <Yuv> almostDecompressed = new List <Yuv>();

            for (int i = 0; i < 256; i++)
            {
                if (indices.Contains(i))
                {
                    almostDecompressed.Add(new Yuv()
                    {
                        Y = Ys.ToList()[i],
                        U = Us.ToList()[i],
                        V = Vs.ToList()[i]
                    });
                }
                else
                {
                    almostDecompressed.Add(new Yuv()
                    {
                        Y = Ys.ToList()[i],
                        U = (byte)LagrangePolynomial.CalculateLagrangePolynomialValue(i, UlagrangeTable),
                        V = (byte)LagrangePolynomial.CalculateLagrangePolynomialValue(i, VlagrangeTable)
                    });
                }
            }
            var rgb = this.ColorTransformer.ConvertYuvToRgb(almostDecompressed);

            foreach (var value in rgb)
            {
                yield return(value.R);

                yield return(value.G);

                yield return(value.B);
            }
        }