当前位置: 首页>>代码示例>>C#>>正文


C# Numerics.Complex类代码示例

本文整理汇总了C#中System.Numerics.Complex的典型用法代码示例。如果您正苦于以下问题:C# System.Numerics.Complex类的具体用法?C# System.Numerics.Complex怎么用?C# System.Numerics.Complex使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


System.Numerics.Complex类属于命名空间,在下文中一共展示了System.Numerics.Complex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddArrays

        /// <summary>
        /// Does a point wise add of two arrays <c>z = x + y</c>. This can be used
        /// to add vectors or matrices.
        /// </summary>
        /// <param name="x">The array x.</param>
        /// <param name="y">The array y.</param>
        /// <param name="result">The result of the addition.</param>
        /// <remarks>There is no equivalent BLAS routine, but many libraries
        /// provide optimized (parallel and/or vectorized) versions of this
        /// routine.</remarks>
        public virtual void AddArrays(Complex[] x, Complex[] y, Complex[] result)
        {
            if (y == null)
            {
                throw new ArgumentNullException("y");
            }

            if (x == null)
            {
                throw new ArgumentNullException("x");
            }

            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            if (y.Length != x.Length || y.Length != result.Length)
            {
                throw new ArgumentException(Resources.ArgumentVectorsSameLength);
            }

            CommonParallel.For(0, y.Length, 4096, (a, b) =>
            {
                for (int i = a; i < b; i++)
                {
                    result[i] = x[i] + y[i];
                }
            });
        }
开发者ID:EraYaN,项目名称:EV2020,代码行数:40,代码来源:ManagedLinearAlgebraProvider.Complex.cs

示例2: BackwardReal

        public void BackwardReal(double[] spectrum, int n, FourierTransformScaling scaling)
        {
            // TODO: backport proper, optimized implementation from Iridium

            Complex[] data = new Complex[n];
            data[0] = new Complex(spectrum[0], 0d);
            for (int i = 1, j = 2; i < data.Length/2; i++)
            {
                data[i] = new Complex(spectrum[j++], spectrum[j++]);
                data[data.Length - i] = data[i].Conjugate();
            }
            if (n.IsEven())
            {
                data[data.Length/2] = new Complex(spectrum[n], 0d);
            }
            else
            {
                data[data.Length/2] = new Complex(spectrum[n-1], spectrum[n]);
                data[data.Length/2 + 1] = data[data.Length/2].Conjugate();
            }

            Backward(data, scaling);

            for (int i = 0; i < data.Length; i++)
            {
                spectrum[i] = data[i].Real;
            }
            spectrum[n] = 0d;
        }
开发者ID:RVShershnev,项目名称:mathnet-numerics,代码行数:29,代码来源:ManagedFourierTransformProvider.cs

示例3: Abs

        /// <summary>
        ///   Computes the absolute value of an array of complex numbers.
        /// </summary>
        /// 
        public static Complex[] Abs(this Complex[] x)
        {
            if (x == null) throw new ArgumentNullException("x");

            Complex[] r = new Complex[x.Length];
            for (int i = 0; i < x.Length; i++)
                r[i] = new Complex(x[i].Magnitude, 0);
            return r;
        }
开发者ID:RLaumeyer,项目名称:framework,代码行数:13,代码来源:Matrix.Complex.cs

示例4: CompilerOutput

        public CompilerOutput(string input, Tokens tokens, System.Numerics.Complex returnVal, ParseTree parseTree, 
			PostfixedTokens postFixedTokens, string output)
        {
            this.Input = input;
                this.Tokens = tokens;
                this.ReturnValue = returnVal;
                this.ParseTree = parseTree;
                this.PostFixedTokens = postFixedTokens;
                this.Output = output;
        }
开发者ID:Amichai,项目名称:PhysicsPad,代码行数:10,代码来源:Expression.cs

示例5: findRecurringCycleLength

        static int findRecurringCycleLength(int number)
        {
            //string numString = Decimal.Round((1 / (decimal)number), 28).ToString();
            string numString = (1 / (decimal)number).ToString();

            System.Numerics.Complex numerator = new System.Numerics.Complex(1, 1);
            System.Numerics.Complex denominator = new System.Numerics.Complex(number, number);

            System.Numerics.Complex muh = numerator / denominator;
            return 0;
        }
开发者ID:nubington,项目名称:projecteuler,代码行数:11,代码来源:Program.cs

示例6: Multiply

        /// <summary>
        ///   Elementwise multiplication of two complex vectors.
        /// </summary>
        /// 
        public static Complex[] Multiply(this Complex[] a, Complex[] b)
        {
            if (a == null) throw new ArgumentNullException("a");
            if (b == null) throw new ArgumentNullException("b");

            Complex[] r = new Complex[a.Length];
            for (int i = 0; i < a.Length; i++)
            {
                r[i] = Complex.Multiply(a[i], b[i]);
            }
            return r;
        }
开发者ID:RLaumeyer,项目名称:framework,代码行数:16,代码来源:Matrix.Complex.cs

示例7: BluesteinSequence

        /// <summary>
        /// Generate the bluestein sequence for the provided problem size.
        /// </summary>
        /// <param name="n">Number of samples.</param>
        /// <returns>Bluestein sequence exp(I*Pi*k^2/N)</returns>
        private static Complex[] BluesteinSequence(int n)
        {
            double s = Constants.Pi / n;
            var sequence = new Complex[n];

            for (int k = 0; k < sequence.Length; k++)
            {
                double t = s * (k * k);
                sequence[k] = new Complex(Math.Cos(t), Math.Sin(t));
            }

            return sequence;
        }
开发者ID:koponk,项目名称:mathnet-numerics,代码行数:18,代码来源:DiscreteFourierTransform.Bluestein.cs

示例8: ForwardScaleByOptions

        /// <summary>
        /// Rescale FFT-the resulting vector according to the provided convention options.
        /// </summary>
        /// <param name="options">Fourier Transform Convention Options.</param>
        /// <param name="samples">Sample Vector.</param>
        private static void ForwardScaleByOptions(FourierOptions options, Complex[] samples)
        {
            if ((options & FourierOptions.NoScaling) == FourierOptions.NoScaling ||
                (options & FourierOptions.AsymmetricScaling) == FourierOptions.AsymmetricScaling)
            {
                return;
            }

            var scalingFactor = Math.Sqrt(1.0 / samples.Length);
            for (int i = 0; i < samples.Length; i++)
            {
                samples[i] *= scalingFactor;
            }
        }
开发者ID:nakamoton,项目名称:mathnet-numerics,代码行数:19,代码来源:DiscreteFourierTransform.Options.cs

示例9: BluesteinConvolutionParallel

        /// <summary>
        /// Convolution with the bluestein sequence (Parallel Version).
        /// </summary>
        /// <param name="samples">Sample Vector.</param>
        private static void BluesteinConvolutionParallel(Complex[] samples)
        {
            int n = samples.Length;
            Complex[] sequence = BluesteinSequence(n);

            // Padding to power of two >= 2N–1 so we can apply Radix-2 FFT.
            int m = ((n << 1) - 1).CeilingToPowerOfTwo();
            Complex[] b = new Complex[m];
            Complex[] a = new Complex[m];

            CommonParallel.Invoke(
                () =>
                {
                    // Build and transform padded sequence b_k = exp(I*Pi*k^2/N)
                    for (int i = 0; i < n; i++)
                    {
                        b[i] = sequence[i];
                    }

                    for (int i = m - n + 1; i < b.Length; i++)
                    {
                        b[i] = sequence[m - i];
                    }

                    Radix2(b, -1);
                },
                () =>
                {
                    // Build and transform padded sequence a_k = x_k * exp(-I*Pi*k^2/N)
                    for (int i = 0; i < samples.Length; i++)
                    {
                        a[i] = sequence[i].Conjugate() * samples[i];
                    }

                    Radix2(a, -1);
                });

            for (int i = 0; i < a.Length; i++)
            {
                a[i] *= b[i];
            }

            Radix2Parallel(a, 1);

            var nbinv = 1.0 / m;
            for (int i = 0; i < samples.Length; i++)
            {
                samples[i] = nbinv * sequence[i].Conjugate() * a[i];
            }
        }
开发者ID:koponk,项目名称:mathnet-numerics,代码行数:54,代码来源:DiscreteFourierTransform.Bluestein.cs

示例10: Backward

 public void Backward(Complex[] spectrum, FourierTransformScaling scaling)
 {
     switch (scaling)
     {
         case FourierTransformScaling.SymmetricScaling:
             Fourier.BluesteinInverse(spectrum, FourierOptions.Default);
             break;
         case FourierTransformScaling.BackwardScaling:
             Fourier.BluesteinInverse(spectrum, FourierOptions.AsymmetricScaling);
             break;
         default:
             Fourier.BluesteinInverse(spectrum, FourierOptions.NoScaling);
             break;
     }
 }
开发者ID:RVShershnev,项目名称:mathnet-numerics,代码行数:15,代码来源:ManagedFourierTransformProvider.cs

示例11: Hypotenuse

        /// <summary>
        /// Numerically stable hypotenuse of a right angle triangle, i.e. <code>(a,b) -> sqrt(a^2 + b^2)</code>
        /// </summary>
        /// <param name="a">The length of side a of the triangle.</param>
        /// <param name="b">The length of side b of the triangle.</param>
        /// <returns>Returns <code>sqrt(a<sup>2</sup> + b<sup>2</sup>)</code> without underflow/overflow.</returns>
        public static Complex Hypotenuse(Complex a, Complex b)
        {
            if (a.Magnitude > b.Magnitude)
            {
                var r = b.Magnitude / a.Magnitude;
                return a.Magnitude * Math.Sqrt(1 + (r * r));
            }

            if (b != 0.0)
            {
                // NOTE (ruegg): not "!b.AlmostZero()" to avoid convergence issues (e.g. in SVD algorithm)
                var r = a.Magnitude / b.Magnitude;
                return b.Magnitude * Math.Sqrt(1 + (r * r));
            }

            return 0d;
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:23,代码来源:Stability.cs

示例12: Main

        static void Main(string [] args)
        {
            using (Lua lua = new Lua())
             		{
             lua.DebugHook += DebugHook;
             lua.SetDebugHook (NLua.Event.EventMasks.LUA_MASKLINE, 0);
             var a = new System.Numerics.Complex (10, 0);
             var b = new System.Numerics.Complex (0, 3);
             var x = a + b;

            // lua.LoadCLRPackage ();
             lua ["a"] = a;
             lua ["b"] = 1;
             var res = lua.DoString (@"return a + b")[0];

             		}
        }
开发者ID:BlackNecro,项目名称:NLua,代码行数:17,代码来源:Program.cs

示例13: InverseScaleByOptions

        /// <summary>
        /// Rescale the iFFT-resulting vector according to the provided convention options.
        /// </summary>
        /// <param name="options">Fourier Transform Convention Options.</param>
        /// <param name="samples">Sample Vector.</param>
        private static void InverseScaleByOptions(FourierOptions options, Complex[] samples)
        {
            if ((options & FourierOptions.NoScaling) == FourierOptions.NoScaling)
            {
                return;
            }

            var scalingFactor = 1.0 / samples.Length;
            if ((options & FourierOptions.AsymmetricScaling) != FourierOptions.AsymmetricScaling)
            {
                scalingFactor = Math.Sqrt(scalingFactor);
            }

            for (int i = 0; i < samples.Length; i++)
            {
                samples[i] *= scalingFactor;
            }
        }
开发者ID:nakamoton,项目名称:mathnet-numerics,代码行数:23,代码来源:DiscreteFourierTransform.Options.cs

示例14: Bluestein

        /// <summary>
        /// Bluestein generic FFT for arbitrary sized sample vectors.
        /// </summary>
        /// <param name="samples">Time-space sample vector.</param>
        /// <param name="exponentSign">Fourier series exponent sign.</param>
        internal static void Bluestein(Complex[] samples, int exponentSign)
        {
            int n = samples.Length;
            if (n.IsPowerOfTwo())
            {
                Radix2(samples, exponentSign);
                return;
            }

            if (exponentSign == 1)
            {
                SwapRealImaginary(samples);
            }

            BluesteinConvolutionParallel(samples);

            if (exponentSign == 1)
            {
                SwapRealImaginary(samples);
            }
        }
开发者ID:nakamoton,项目名称:mathnet-numerics,代码行数:26,代码来源:DiscreteFourierTransform.Bluestein.cs

示例15: AddArrays

        /// <summary>
        /// Does a point wise add of two arrays <c>z = x + y</c>. This can be used 
        /// to add vectors or matrices.
        /// </summary>
        /// <param name="x">The array x.</param>
        /// <param name="y">The array y.</param>
        /// <param name="result">The result of the addition.</param>
        /// <remarks>There is no equivalent BLAS routine, but many libraries
        /// provide optimized (parallel and/or vectorized) versions of this
        /// routine.</remarks>
        public virtual void AddArrays(Complex[] x, Complex[] y, Complex[] result)
        {
            if (y == null)
            {
                throw new ArgumentNullException("y");
            }

            if (x == null)
            {
                throw new ArgumentNullException("x");
            }

            if (result == null)
            {
                throw new ArgumentNullException("result");
            }

            if (y.Length != x.Length || y.Length != result.Length)
            {
                throw new ArgumentException(Resources.ArgumentVectorsSameLength);
            }

            if (Control.ParallelizeOperation(x.Length))
            {
                CommonParallel.For(0, y.Length, 4096, (a, b) =>
                    {
                        for (int i = a; i < b; i++)
                        {
                            result[i] = x[i] + y[i];
                        }
                    });
            }
            else
            {
                for (var index = 0; index < x.Length; index++)
                {
                    result[index] = x[index] + y[index];
                }
            }
        }
开发者ID:nakamoton,项目名称:mathnet-numerics,代码行数:50,代码来源:ManagedLinearAlgebraProvider.Complex.cs


注:本文中的System.Numerics.Complex类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。