• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Numerics.Complex类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: GetFilter

        public static Complex[,] GetFilter(double[,] arr)
        {
            int xLength = arr.GetLength(0) - 2 * arr.GetLength(0) / 2 == 0 ? arr.GetLength(0) + 1 : arr.GetLength(0);
            int yLength = arr.GetLength(1) - 2 * arr.GetLength(1) / 2 == 0 ? arr.GetLength(1) + 1 : arr.GetLength(1);
            int upperBoundX = (int)(xLength / 2);
            int lowerBoundX = -1 * upperBoundX;
            int upperBoundY = (int)(yLength / 2);
            int lowerBoundY = -1 * upperBoundY;

            Complex[,] filter = new Complex[xLength, yLength];
            double x_, y_ = 0;

            for (int x = lowerBoundX; x < upperBoundX; x++)
            {
                for (int y = lowerBoundY; y < upperBoundY; y++)
                {
                    if (y < 0)
                    {
                        filter[upperBoundX + x, upperBoundY + y] = 0;
                        continue;
                    }

                    x_ = XY_WithLine.GetX_WithLine(upperBoundX + x, upperBoundY + y);
                    y_ = XY_WithLine.GetY_WithLine(upperBoundX + x, upperBoundY + y);
                    filter[upperBoundX + x, upperBoundY + y] = 
                        (2 * x_ * y_ + Complex.ImaginaryOne * (x_ * x_ - y_ * y_)) * Gaussian.CalculateGaussian(x_, y_);
                }
            }

            return filter;
        }
开发者ID:Cool2Feel,项目名称:cuda-fingerprinting,代码行数:31,代码来源:Filter.cs


示例2: ForwardInplaceRealSine

        public void ForwardInplaceRealSine()
        {
            var samples = Generate.PeriodicMap(16, w => new Complex(Math.Sin(w), 0), 16, 1.0, Constants.Pi2);
            var spectrum = new Complex[samples.Length];

            // real-odd transforms to imaginary odd
            samples.Copy(spectrum);
            Control.FourierTransformProvider.Forward(spectrum, FourierTransformScaling.BackwardScaling);

            // all real components must be zero
            foreach (var c in spectrum)
            {
                Assert.AreEqual(0, c.Real, 1e-12, "real");
            }

            // all imaginary components except second and last musth be zero
            for (var i = 0; i < spectrum.Length; i++)
            {
                if (i == 1)
                {
                    Assert.AreEqual(-8, spectrum[i].Imaginary, 1e-12, "imag second");
                }
                else if (i == spectrum.Length - 1)
                {
                    Assert.AreEqual(8, spectrum[i].Imaginary, 1e-12, "imag last");
                }
                else
                {
                    Assert.AreEqual(0, spectrum[i].Imaginary, 1e-12, "imag");
                }
            }
        }
开发者ID:RVShershnev,项目名称:mathnet-numerics,代码行数:32,代码来源:FourierTransformProviderTests.cs


示例3: CalculateFastFourierTransform

        /// <summary>
        /// The fourier transform.
        /// </summary>
        /// <param name="characteristics">
        /// The characteristics.
        /// </param>
        /// <returns>
        /// Spectrum of the signal as <see cref="T:double[][]"/>.
        /// </returns>
        public static double[][] CalculateFastFourierTransform(double[][] characteristics)
        {
            var powerOfTwo = PowerOfTwoCeiling(characteristics.Length);
            var result = new double[powerOfTwo][];
            for (int j = 0; j < powerOfTwo; j++)
            {
                result[j] = new double[characteristics[0].Length];
            }

            // transforming into complex representation
            // cycle through all characteristics
            for (int i = 0; i < characteristics[0].Length; i++)
            {
                var complex = new Complex[powerOfTwo];

                // cycle through all sequence fragments
                for (int j = 0; j < powerOfTwo; j++)
                {
                    complex[j] = j < characteristics.Length ? new Complex(characteristics[j][i], 0) : new Complex(0, 0);
                }

                Complex[] complexResult = CalculateFastFourierTransform(complex);

                // converting array to double
                for (int g = 0; g < powerOfTwo; g++)
                {
                    result[g][i] = complexResult[g].Real;
                }
            }

            return result;
        }
开发者ID:intervals-mining-lab,项目名称:libiada-web,代码行数:41,代码来源:FastFourierTransform.cs


示例4: IsMemberRecursive

        /// <summary>
        /// Recursive solution to determine whether complex number belongs to the Mandelbrot set
        /// </summary>
        public MandelbrotResult IsMemberRecursive(Complex c, Complex? z = null, int iteration = 0)
        {
            if (iteration == MaxIterations) return new MandelbrotResult(iteration, true);
            if (z.HasValue && z.Value.Magnitude > 2.0) return new MandelbrotResult(iteration, false);

            var newZ = z.HasValue ? Complex.Pow(z.Value, 2) + c : Complex.Zero;
            return IsMemberRecursive(c, newZ, iteration + 1);
        }
开发者ID:ChrisFulstow,项目名称:Simulacrum,代码行数:11,代码来源:MandelbrotSolver.cs


示例5: Mobius

 public Mobius( Complex a, Complex b, Complex c, Complex d )
     : this()
 {
     A = a;
     B = b;
     C = c;
     D = d;
 }
开发者ID:roice3,项目名称:Honeycombs,代码行数:8,代码来源:Mobius.cs


示例6: ComparePowIntWithPow

        public void ComparePowIntWithPow()
        {
            Complex z1 = new Complex(1.6859, 0.3902);
            Complex actual = z1.Pow(10);
            Complex expected = z1 * z1 * z1 * z1 * z1 * z1 * z1 * z1 * z1 * z1;

            Assert.IsTrue(expected.ApproximatelyEquals(actual, epsilon));
        }
开发者ID:rodriada000,项目名称:Mathos-Project,代码行数:8,代码来源:ComplexArithmeticTest.cs


示例7: Create

        public static PyComplexObject Create(DkmProcess process, Complex value) {
            var allocator = process.GetDataItem<PyObjectAllocator>();
            Debug.Assert(allocator != null);

            var result = allocator.Allocate<PyComplexObject>();
            result.cval.real.Write(value.Real);
            result.cval.imag.Write(value.Imaginary);
            return result;
        }
开发者ID:omnimark,项目名称:PTVS,代码行数:9,代码来源:PyComplexObject.cs


示例8: PorousMatrix

            public static SparseMatrix PorousMatrix(bool Rigid, double d, Complex k, Complex sin_theta, double freq, double porosity, double tortuosity, double YoungsModulus, double PoissonRatio, double Viscous_Characteristic_Length, double flow_resistivity, double FrameDensity, double Thermal_Permeability_0, double AmbientMeanPressure)
            {
                double w = Utilities.Numerics.PiX2 * freq;
                double v = Biot_Porous_Absorbers.v();
                double FrameShear = AbsorptionModels.Biot_Porous_Absorbers.Shear_Modulus(YoungsModulus, PoissonRatio);
                double kb = 2 * FrameShear * (PoissonRatio + 1) / (3 * (1 - 2 * PoissonRatio));
                double BulkMod_Frame = AbsorptionModels.Biot_Porous_Absorbers.BulkMod_Solid(YoungsModulus, PoissonRatio);
                Complex Kf = Biot_Porous_Absorbers.BulkMod_Fluid(w, AmbientMeanPressure, porosity, Thermal_Permeability_0);//AmbientMeanPressure / (1 - (gamma - 1) / (gamma * alpha));
                Complex LameL = YoungsModulus * PoissonRatio / ((1 + PoissonRatio) * (1 - 2 * PoissonRatio));
                Complex LameMu = YoungsModulus / (2 * (1 + PoissonRatio));
                Complex delta21 = w * w * FrameDensity;
                Complex delta22 = w * w * FrameDensity;
                Complex delta23 = delta21 / LameMu;
                delta21 /= (LameL + 2 * LameMu);
                delta22 /= (LameL + 2 * LameMu);

                //Taken from Lauriks, et. al., 1990.
                double rho12 = Biot_Porous_Absorbers.rho12(porosity, tortuosity);
                double rhoa = Biot_Porous_Absorbers.rhoA(rho12);
                double Viscous_Permeability = Biot_Porous_Absorbers.Viscous_Permeability(flow_resistivity);
                Complex Gw = Biot_Porous_Absorbers.G_w(tortuosity, porosity, Viscous_Permeability, Viscous_Characteristic_Length, freq, v);

                //Complex rho12eff = Biot_Porous_Absorbers.rho12eff(rhoa, porosity, flow_resistivity, Gw, freq);
                Complex rho22eff = Biot_Porous_Absorbers.rho22eff(rhoa, porosity, flow_resistivity, Gw, freq);
                Complex rho11eff = Biot_Porous_Absorbers.rho11eff(FrameDensity, rhoa, porosity, flow_resistivity, Gw, freq);

                Complex P, Q, R;

                if (!Rigid)
                {
                    //Universal (Limp) Frame Case:
                    P = ((1 - porosity) * (1 - kb / BulkMod_Frame) * BulkMod_Frame + porosity * BulkMod_Frame * kb / Kf) / (1 - porosity - kb / BulkMod_Frame + porosity * BulkMod_Frame / Kf);
                    Q = (1 - porosity - kb / BulkMod_Frame) * porosity * BulkMod_Frame / (1 - porosity - kb / BulkMod_Frame + porosity * BulkMod_Frame / Kf);
                    R = porosity * porosity * BulkMod_Frame / (1 - porosity - kb / BulkMod_Frame + porosity * BulkMod_Frame / Kf);
                }
                else
                {
                    //Rigid Frame Case:
                    P = 4 * FrameShear / 3 + kb + (porosity * porosity) * Kf / porosity;
                    R = porosity * Kf;
                    Q = Kf * (1 - porosity);
                }

                Complex kt = k * sin_theta;
                Complex k13 = Complex.Sqrt(delta21 - kt * kt);
                Complex k23 = Complex.Sqrt(delta22 - kt * kt);
                Complex k33 = Complex.Sqrt(delta23 - kt * kt);
                Complex Mu1 = Q * delta21 - w * w * rho11eff / (w * w * rho22eff - R * delta21);
                Complex Mu2 = Q * delta22 - w * w * rho11eff / (w * w * rho22eff - R * delta22);
                Complex Mu3 = FrameShear * delta23 - w * w * rho11eff / (w * w * rho22eff);

                SparseMatrix GH = GammaH_P(kt, w, d, FrameShear, P, Q, R, k13, k23, k33, Mu1, Mu2, Mu3);
                SparseMatrix G0T = Gamma0T_P(kt, w, FrameShear, P, Q, R, k13, k23, k33, Mu1, Mu2, Mu3);

                return GH * G0T;

            }
开发者ID:MengdiGuo,项目名称:PachydermAcoustic_Rhinoceros,代码行数:57,代码来源:Classes_Absorption_Matrices.cs


示例9: TestIfMulIsEqualToComplexOperator

        public void TestIfMulIsEqualToComplexOperator()
        {
            var z1 = new Complex(1.6859, 0.3902);
            var z2 = new Complex(3.51896, -0.458);

            var w1 = z1 * z2;
            var w2 = ComplexArithmetic.Multiply(z1, z2);

            Assert.IsTrue(w1.ApproximatelyEquals(w2, Epsilon));
        }
开发者ID:furesoft,项目名称:Mathos-Project,代码行数:10,代码来源:ComplexArithmeticTest.cs


示例10: TestIfPowIntInFasterThanPow

        public void TestIfPowIntInFasterThanPow()
        {
            int iter = 250000;
            Complex z = new Complex(1.6859, 0.3902);
            double averageIntTime = BenchmarkUtil.Benchmark(
                () => { Complex w = ComplexArithmetic.PowInt(z, 10); }, iter);
            double averageCpTime = BenchmarkUtil.Benchmark(
                () => { Complex w = Complex.Pow(z, 10); }, iter);

            Assert.IsTrue(averageIntTime < averageCpTime);
        }
开发者ID:rodriada000,项目名称:Mathos-Project,代码行数:11,代码来源:ComplexArithmeticTest.cs


示例11: IsMemberIterative

 public MandelbrotResult IsMemberIterative(Complex c)
 {
     var iteration = 0;
     var z = Complex.Zero;
     while (iteration < MaxIterations && z.Magnitude < 2)
     {
         z = z * z + c;
         iteration++;
     }
     var isMember = (iteration == MaxIterations);
     return new MandelbrotResult(iteration, isMember);
 }
开发者ID:ChrisFulstow,项目名称:Simulacrum,代码行数:12,代码来源:MandelbrotSolver.cs


示例12: FourierRadix2IsReversible

        public void FourierRadix2IsReversible(FourierOptions options)
        {
            var samples = Generate.RandomComplex(0x8000, GetUniform(1));
            var work = new Complex[samples.Length];
            samples.CopyTo(work, 0);

            Fourier.Radix2Forward(work, options);
            Assert.IsFalse(work.ListAlmostEqual(samples, 6));

            Fourier.Radix2Inverse(work, options);
            AssertHelpers.AlmostEqual(samples, work, 12);
        }
开发者ID:Jungwon,项目名称:mathnet-numerics,代码行数:12,代码来源:InverseTransformTest.cs


示例13: Filtering

        /// <summary>
        /// Тихоновская регуляризация
        /// </summary>
        /// <param name="filter"> ядро искажения (PSF)</param>
        /// <returns></returns>
        public static ConvolutionFilter Filtering(ConvolutionFilter filter)
        {
            ///в частотной области
            ///fn(u,v)=((h*(u,v)/|h(u,v)|^2+gamma*|p(u,v)|^2))*g(u,v)
            ///fn - приближение
            ///h - kernel
            ///h* - комплексно-сопряженная форма kernel
            ///|h|^2 = h(u,v)*h*(u,v) = u^2+v^2*i
            ///gamma - какой-то параметр (в инверсном фильтре = 0)
            ///p(u,v) = оператор Лапласа = [{0  1  0}
            ///                             {1 -4  1}
            ///                             {0  1  0}]
            ///g - искаженное изображение

            Complex[,] otf = OpticalTransferFunction.Psf2otf(filter);
            int height = otf.GetLength(0);                                              //строк
            int width = otf.GetLength(1);                                              //столбцов
            Complex gamma = Complex.Zero;                                        //
            Complex[,] otfZ = new Complex[height, width];                                   //комплексно сопряженная матрица ядра
            Complex[,] otf2 = new Complex[height, width];                                   //матрица = |h|^2
            Complex[,] p = {{0, 1, 0,},                                          //лапласиан
                           {1, -4, 1,},
                           {0, 1, 0,},};
            p = Fourier.Transform(p);
            for (int u = 0; u < p.GetLength(0); u++)
                for (int v = 0; v < p.GetLength(1); v++)
                    p[u, v] = OpticalTransferFunction.ModPow(p[u, v]);

            for (int u = 0; u < height; u++)
                for (int v = 0; v < width; v++)
                    otfZ[u, v] = Complex.Conjugate(otf[u, v]);

            for (int u = 0; u < height; u++)
                for (int v = 0; v < width; v++)
                    otf2[u, v] = OpticalTransferFunction.ModPow(otf[u, v]);

            for (int u = 0; u < height; u++)
                for (int v = 0; v < width; v++)
                    p[u, v] = p[u, v] * gamma;

            for (int u = 0; u < height; u++)
                for (int v = 0; v < width; v++)
                    otf2[u, v] = otf2[u, v] + p[u, v];

            for (int u = 0; u < height; u++)
                for (int v = 0; v < width; v++)
                    otf[u, v] = otfZ[u, v] / otf2[u, v];

            ConvolutionFilter cf = OpticalTransferFunction.Otf2psf(otf);

            return cf;
        }
开发者ID:xsimbvx,项目名称:ImageRecovery,代码行数:57,代码来源:TikhonovFiltering.cs


示例14: CreateSinglePoint

 protected override IterateSinglePointResult? CreateSinglePoint(
     Complex current,
     Complex parameter,
     int maxIterations,
     double maxMagnitude)
 {
     return this.IterateSinglePoint(
         initial: current,
         offset: parameter,
         returnValue: current,
         maxIterations: maxIterations,
         maxMagnitude: maxMagnitude);
 }
开发者ID:piotrosz,项目名称:Julia-and-Mandelbrot,代码行数:13,代码来源:JuliaSet.cs


示例15: FourierBluesteinIsReversible

        public void FourierBluesteinIsReversible(FourierOptions options)
        {
            var dft = new DiscreteFourierTransform();

            var samples = Generate.RandomComplex(0x7FFF, GetUniform(1));
            var work = new Complex[samples.Length];
            samples.CopyTo(work, 0);

            dft.BluesteinForward(work, options);
            Assert.IsFalse(work.ListAlmostEqual(samples, 6));

            dft.BluesteinInverse(work, options);
            AssertHelpers.ListAlmostEqual(samples, work, 10);
        }
开发者ID:rookboom,项目名称:mathnet-numerics,代码行数:14,代码来源:InverseTransformTest.cs


示例16: UserCholesky

        /// <summary>
        /// Initializes a new instance of the <see cref="UserCholesky"/> class. This object will compute the
        /// Cholesky factorization when the constructor is called and cache it's factorization.
        /// </summary>
        /// <param name="matrix">The matrix to factor.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="matrix"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="matrix"/> is not a square matrix.</exception>
        /// <exception cref="ArgumentException">If <paramref name="matrix"/> is not positive definite.</exception>
        public UserCholesky(Matrix<Complex> matrix)
        {
            if (matrix == null)
            {
                throw new ArgumentNullException("matrix");
            }

            if (matrix.RowCount != matrix.ColumnCount)
            {
                throw new ArgumentException(Resources.ArgumentMatrixSquare);
            }

            // Create a new matrix for the Cholesky factor, then perform factorization (while overwriting).
            CholeskyFactor = matrix.Clone();
            var tmpColumn = new Complex[CholeskyFactor.RowCount];

            // Main loop - along the diagonal
            for (var ij = 0; ij < CholeskyFactor.RowCount; ij++)
            {
                // "Pivot" element
                var tmpVal = CholeskyFactor.At(ij, ij);

                if (tmpVal.Real > 0.0)
                {
                    tmpVal = tmpVal.SquareRoot();
                    CholeskyFactor.At(ij, ij, tmpVal);
                    tmpColumn[ij] = tmpVal;

                    // Calculate multipliers and copy to local column
                    // Current column, below the diagonal
                    for (var i = ij + 1; i < CholeskyFactor.RowCount; i++)
                    {
                        CholeskyFactor.At(i, ij, CholeskyFactor.At(i, ij) / tmpVal);
                        tmpColumn[i] = CholeskyFactor.At(i, ij);
                    }

                    // Remaining columns, below the diagonal
                    DoCholeskyStep(CholeskyFactor, CholeskyFactor.RowCount, ij + 1, CholeskyFactor.RowCount, tmpColumn, Control.NumberOfParallelWorkerThreads);
                }
                else
                {
                    throw new ArgumentException(Resources.ArgumentMatrixPositiveDefinite);
                }

                for (var i = ij + 1; i < CholeskyFactor.RowCount; i++)
                {
                    CholeskyFactor.At(ij, i, Complex.Zero);
                }
            }
        }
开发者ID:koponk,项目名称:mathnet-numerics,代码行数:58,代码来源:UserCholesky.cs


示例17: GenerateRandomDenseVector

        public static Vector<Complex> GenerateRandomDenseVector(int order)
        {
            // Fill a matrix with standard random numbers.
            var normal = new Distributions.Normal
                         {
                             RandomSource = new Random.MersenneTwister(1)
                         };
            var v = new DenseVector(order);
            for (var i = 0; i < order; i++)
            {
                v[i] = new Complex(normal.Sample(), normal.Sample());
            }

            // Generate a matrix which is positive definite.
            return v;
        }
开发者ID:xmap2008,项目名称:mathnet-numerics,代码行数:16,代码来源:MatrixLoader.cs


示例18: FourierDefaultTransformSatisfiesParsevalsTheorem

        public void FourierDefaultTransformSatisfiesParsevalsTheorem(int count)
        {
            var samples = Generate.RandomComplex(count, GetUniform(1));

            var timeSpaceEnergy = (from s in samples select s.MagnitudeSquared()).Mean();

            var work = new Complex[samples.Length];
            samples.CopyTo(work, 0);

            // Default -> Symmetric Scaling
            Fourier.Forward(work);

            var frequencySpaceEnergy = (from s in work select s.MagnitudeSquared()).Mean();

            Assert.AreEqual(timeSpaceEnergy, frequencySpaceEnergy, 1e-12);
        }
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:16,代码来源:ParsevalTheoremTest.cs


示例19: FourierDefaultTransformSatisfiesParsevalsTheorem

        public void FourierDefaultTransformSatisfiesParsevalsTheorem(int count)
        {
            var samples = Sample.Random((u, v) => new Complex(u, v), _uniform, count);

            var timeSpaceEnergy = (from s in samples select s.MagnitudeSquared()).Mean();

            var work = new Complex[samples.Length];
            samples.CopyTo(work, 0);

            // Default -> Symmetric Scaling
            Transform.FourierForward(work);

            var frequencySpaceEnergy = (from s in work select s.MagnitudeSquared()).Mean();

            Assert.AreApproximatelyEqual(timeSpaceEnergy, frequencySpaceEnergy, 1e-12);
        }
开发者ID:hany-abdelrahman,项目名称:mathnet-numerics,代码行数:16,代码来源:ParsevalTheoremTest.cs


示例20: IterateSinglePoint

 protected IterateSinglePointResult? IterateSinglePoint(
     Complex initial,
     Complex offset,
     Complex returnValue,
     int maxIterations,
     double maxMagnitude)
 {
     var z1 = initial;
     for (int i = 0; i < maxIterations; i++)
     {
         z1 = z1 * z1 + offset;
         if (z1.Magnitude > maxMagnitude)
         {
             return new IterateSinglePointResult { C = returnValue, Iterations = i };
         }
     }
     return null;
 }
开发者ID:piotrosz,项目名称:Julia-and-Mandelbrot,代码行数:18,代码来源:Fractal.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Numerics.Vector类代码示例发布时间:2022-05-26
下一篇:
C# Numerics.BigInteger类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap