Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            float[] x = new float[] { 1, 2, 3 };
            float[] y = new float[] { 2, 4, 6 };

            Polynomial eq = new Polynomial(2);

            eq.SolveLeastSquares(x, y);
            float[] c = eq.Coefficients;
            Console.WriteLine(c[0]);
            Console.WriteLine(c[1]);
            Console.WriteLine(c[2]);

            Console.WriteLine();
            y = new float[] { 0, 2 };
            PolyInterpolation intp = new PolyInterpolation(1);
            float             ynew = intp.UnitInterpolation(0.5f, y);

            Console.WriteLine(ynew);

            Console.WriteLine();
            FourierSeries f = new FourierSeries(1);

            x = new float[] { 0, 0.25f, 0.5f };
            y = new float[] { 1, 2, -1 };
            f.SolveLeastSquares(x, y);
            Console.WriteLine(f.Ak[0]);
            Console.WriteLine(f.Bk[0]);

            Console.Read();
        }
Ejemplo n.º 2
0
 public FourierSeriesViewModel()
 {
     fourierSeries = new FourierSeries
     {
         Function   = new PeriodicFunction((x) => (x)).Invoke,
         Prescision = 1003,
         N          = 10
     };
 }
Ejemplo n.º 3
0
        //public FourierSeries SelectedParameters
        //{
        //    get { return fourierSeries; }
        //    set
        //    {
        //        fourierSeries = value;

        //        OnPropertyChanged();
        //    }
        //}


        public DiscreteSignalsViewModel()
        {
            fourierSeries = new FourierSeries
            {
            };
            GetData();

            UpdateImagePlot();
            CalculateError();
        }
    // Start is called before the first frame update
    public void CalculateFourierSeries(Func <double, double[]> function_to_transform, int max_frequency)
    {
        /*
         * Calculates fourier series of function_to_transform using max_frequency.
         * Uses FourierSeries.cs to accomplish task. Stores the fourier series to be used later for
         * showing the approximation
         */

        temp_position  = transform.position;
        coefficients   = FourierSeries.fft_GetFourierCoefficients(function_to_transform, max_frequency);
        fourier_series = FourierSeries.GetFourierSeries(coefficients);

        line = GetComponent <LineRenderer>();
        line.positionCount = 0;
    }
Ejemplo n.º 5
0
    // Start is called before the first frame update
    public void CalculateFourierSeries(Func <double, double[]> function_to_transform, int max_frequency)
    {
        /*
         * Gets the coefficients of the fourier series of function_to_transform.
         * Is used in making the arrows that track the cumulative movement of each frequency.
         */

        coefficients = FourierSeries.fft_GetFourierCoefficients(function_to_transform, max_frequency);

        //Instantiating required GameObjects

        for (int i = 0; i < (coefficients[0].Count + 1) / 2; i++)
        {
            availableObjects.Add(Instantiate(Prefab, new Vector3(0, 0, 0), Quaternion.identity));
            availableArrows.Add(Instantiate(ArrowPrefab, new Vector3(0, 0, 0), Quaternion.identity));
        }
    }
Ejemplo n.º 6
0
        public FourierSeries Fourier(int nCount)
        {
            FourierSeries fourier = new FourierSeries();

            fourier.a = new List <double>();
            fourier.b = new List <double>();

            fourier.a0 = (1 / a) * IntExpression.calculate();

            for (int n = 1; n < nCount + 1; n++)
            {
                fourier.a.Add((1 / Math.PI) * Integral(intAexpresstion, n));
                fourier.b.Add((1 / Math.PI) * Integral(intBexpresstion, n));
            }

            return(fourier);
        }
Ejemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        time += 0.001;
        if (time > 10)
        {
            time = 0;
        }
        double[] pos = FourierSeries.function(time);
        // Debug.Log(pos[0]+" "+pos[1]+" "+pos[2]);
        temp_position.x = (float)(50 * Math.Sin(5 * time));
        temp_position.y = (float)(50 * Math.Cos(5 * time));
        temp_position.z = (float)(50 * Math.Sin(5 * time));


        transform.position = temp_position;
        line.positionCount++;
        line.SetPosition(line.positionCount - 1, temp_position);
    }
Ejemplo n.º 8
0
        private void Button_Click2(object sender, RoutedEventArgs e)
        {
            labelResult.Content = "";

            a = Convert.ToInt32(textBoxA.Text);
            b = Convert.ToInt32(textBoxB.Text);
            n = Convert.ToInt32(textBoxN.Text);

            Argument nInt = new Argument("n", n);

            IntExpression   = new Expression("int(" + textBox3.Text + ", x, -3.14, 3.14)");
            intAexpresstion = new Expression("int((" + textBox3.Text + ")*(cos(n*x)), x, -3.14, 3.14)", nInt);
            intBexpresstion = new Expression("int((" + textBox3.Text + ")*(sin(n*x)), x, -3.14, 3.14)", nInt);

            res.Clear();


            FourierSeries fourier = Fourier(n);

            for (double x = a; x < b; x += 0.1)
            {
                double fx = 0;

                fx += fourier.a0 / 2;

                for (int i = 0; i < fourier.a.Count; i++)
                {
                    fx += (fourier.a[i] * Math.Cos((i + 1) * x))
                          + (fourier.b[i] * Math.Sin((i + 1) * x));
                }

                res.Add(new Point(x, fx));
            }

            CreateBigGraph("Ряд Фурье");
        }
Ejemplo n.º 9
0
 public FourierSeriesEnumerator(FourierSeries fs)
 {
     _series     = fs;
     _enumerator = fs.Elements.GetEnumerator();
     Current     = (FourierElement)_enumerator.Current;
 }