/// <summary>
        /// Raise this <c>Complex</c> to the given value.
        /// </summary>
        /// <param name="complex">The <see cref="Complex"/> number to perform this operation on.</param>
        /// <param name="exponent">
        /// The exponent.
        /// </param>
        /// <returns>
        /// The complex number raised to the given exponent.
        /// </returns>
        public static Complex Power(this Complex complex, Complex exponent)
        {
            if (complex.IsZero())
            {
                if (exponent.IsZero())
                {
                    return(Complex.One);
                }

                if (exponent.Real > 0d)
                {
                    return(Complex.Zero);
                }

                if (exponent.Real < 0d)
                {
                    return(exponent.Imaginary == 0d
                        ? new Complex(double.PositiveInfinity, 0d)
                        : new Complex(double.PositiveInfinity, double.PositiveInfinity));
                }

                return(new Complex(double.NaN, double.NaN));
            }

            return(Complex.Pow(complex, exponent));
        }
        /// <summary>
        /// Does a point wise power of two arrays <c>z = x ^ y</c>. This can be used
        /// to raise elements of vectors or matrices to the powers of another vector or matrix.
        /// </summary>
        /// <param name="x">The array x.</param>
        /// <param name="y">The array y.</param>
        /// <param name="result">The result of the point wise power.</param>
        /// <remarks>There is no equivalent BLAS routine, but many libraries
        /// provide optimized (parallel and/or vectorized) versions of this
        /// routine.</remarks>
        public void PointWisePowerArrays(Complex[] x, Complex[] y, Complex[] result)
        {
            if (y == null)
            {
                throw new ArgumentNullException(nameof(y));
            }

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

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

            if (y.Length != x.Length || y.Length != result.Length)
            {
                throw new ArgumentException("All vectors must have the same dimensionality.");
            }

            for (int i = 0; i < result.Length; i++)
            {
                result[i] = Complex.Pow(x[i], y[i]);
            }
        }
        /// <summary>
        /// Does a point wise power of two arrays <c>z = x ^ y</c>. This can be used
        /// to raise elements of vectors or matrices to the powers of another vector or matrix.
        /// </summary>
        /// <param name="x">The array x.</param>
        /// <param name="y">The array y.</param>
        /// <param name="result">The result of the point wise power.</param>
        /// <remarks>There is no equivalent BLAS routine, but many libraries
        /// provide optimized (parallel and/or vectorized) versions of this
        /// routine.</remarks>
        public void PointWisePowerArrays(Complex[] x, Complex[] y, Complex[] result)
        {
            if (y == null)
            {
                throw new ArgumentNullException(nameof(y));
            }

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

            if (x.Length != y.Length)
            {
                throw new ArgumentException("The array arguments must have the same length.");
            }

            if (x.Length != result.Length)
            {
                throw new ArgumentException("The array arguments must have the same length.");
            }

            if (_vectorFunctionsMajor != 0 || _vectorFunctionsMinor < 1)
            {
                for (int i = 0; i < y.Length; i++)
                {
                    result[i] = Complex.Pow(x[i], y[i]);
                }

                return;
            }

            SafeNativeMethods.z_vector_power(x.Length, x, y, result);
        }
 /// <summary>
 /// Raise this <c>Complex</c> to the inverse of the given value.
 /// </summary>
 /// <param name="complex">The <see cref="Complex"/> number to perform this operation on.</param>
 /// <param name="rootExponent">
 /// The root exponent.
 /// </param>
 /// <returns>
 /// The complex raised to the inverse of the given exponent.
 /// </returns>
 public static Complex Root(this Complex complex, Complex rootExponent)
 {
     return(Complex.Pow(complex, 1 / rootExponent));
 }
Пример #5
0
 public static Complex Pow(this Complex self, Complex power)
 {
     return(Complex.Pow(self, power));
 }