Ejemplo n.º 1
0
        internal override Symbol PreEval(Symbol x)
        {
            var z = x.ToComplex();

            var r = Math.exp(z.Re);

            if (z.Im != 0.0)
            {
                return(new Complex(r * Math.cos(z.Im), r * Math.sin(z.Im)));
            }

            return(new Complex(r));
        }
Ejemplo n.º 2
0
        internal static void ifft_1d(double[] re, double[] im, int sign)
        {
            double u_r, u_i, w_r, w_i, t_r, t_i;
            int    ln, nv2, k, l, le, le1, j, ip, i, n;

            n = re.Length;

            ln = ( int )(Math.log(( double )n) / Math.log(2) + 0.5);

            nv2 = n / 2;
            j   = 1;

            for (i = 1; i < n; i++)
            {
                if (i < j)
                {
                    t_r = re[i - 1];
                    t_i = im[i - 1];

                    re[i - 1] = re[j - 1];
                    im[i - 1] = im[j - 1];

                    re[j - 1] = t_r;
                    im[j - 1] = t_i;
                }

                k = nv2;

                while (k < j)
                {
                    j = j - k;
                    k = k / 2;
                }

                j = j + k;
            }

            for (l = 1; l <= ln; l++)
            {
                le  = ( int )(Math.exp(( double )l * Math.log(2)) + 0.5);
                le1 = le / 2;
                u_r = 1.0;
                u_i = 0.0;
                w_r = Math.cos(Math.PI / ( double )le1);
                w_i = sign * Math.sin(Math.PI / ( double )le1);

                for (j = 1; j <= le1; j++)
                {
                    for (i = j; i <= n; i += le)
                    {
                        ip  = i + le1;
                        t_r = re[ip - 1] * u_r - u_i * im[ip - 1];
                        t_i = im[ip - 1] * u_r + u_i * re[ip - 1];

                        re[ip - 1] = re[i - 1] - t_r;
                        im[ip - 1] = im[i - 1] - t_i;

                        re[i - 1] = re[i - 1] + t_r;
                        im[i - 1] = im[i - 1] + t_i;
                    }

                    t_r = u_r * w_r - w_i * u_i;
                    u_i = w_r * u_i + w_i * u_r;
                    u_r = t_r;
                }
            }

            if (sign > 0)
            {
                for (i = 0; i < n; i++)
                {
                    re[i] /= n;
                    im[i] /= n;
                }
            }
        }