Пример #1
0
        public static ComplexD Sqrt(ComplexD a)
        {
            ComplexD result = ComplexD.Zero;

            if ((a.Real == 0.0) && (a.Imaginary == 0.0))
            {
                return(result);
            }
            else if (a.Imaginary == 0.0)
            {
                result.Real      = System.Math.Sqrt(a.Real);
                result.Imaginary = 0.0;
            }
            else
            {
                double modulus = a.GetModulus();

                result.Real      = System.Math.Sqrt(0.5 * (modulus + a.Real));
                result.Imaginary = System.Math.Sqrt(0.5 * (modulus + a.Real));
                if (a.Imaginary < 0.0)
                {
                    result.Imaginary = -result.Imaginary;
                }
            }

            return(result);
        }
Пример #2
0
        public static ComplexD Log(ComplexD a)
        {
            ComplexD result = ComplexD.Zero;

            if ((a.Real > 0.0) && (a.Imaginary == 0.0))
            {
                result.Real      = System.Math.Log(a.Real);
                result.Imaginary = 0.0;
            }
            else if (a.Real == 0.0)
            {
                if (a.Imaginary > 0.0)
                {
                    result.Real      = System.Math.Log(a.Imaginary);
                    result.Imaginary = MathFunctions.HalfPI;
                }
                else
                {
                    result.Real      = System.Math.Log(-(a.Imaginary));
                    result.Imaginary = -MathFunctions.HalfPI;
                }
            }
            else
            {
                result.Real      = System.Math.Log(a.GetModulus());
                result.Imaginary = System.Math.Atan2(a.Imaginary, a.Real);
            }

            return(result);
        }
Пример #3
0
        /// <summary>
        /// Multiplies two complex numbers.
        /// </summary>
        /// <param name="a">A <see cref="ComplexD"/> instance.</param>
        /// <param name="b">A <see cref="ComplexD"/> instance.</param>
        /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
        public static ComplexD Multiply(ComplexD a, ComplexD b)
        {
            // (x + yi)(u + vi) = (xu � yv) + (xv + yu)i.
            double x = a.Real, y = a.Imaginary;
            double u = b.Real, v = b.Imaginary;

            return(new ComplexD(x * u - y * v, x * v + y * u));
        }
Пример #4
0
 /// <summary>
 /// Tests whether two complex numbers are approximately equal given a tolerance value.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="b">A <see cref="ComplexD"/> instance.</param>
 /// <param name="tolerance">The tolerance value used to test approximate equality.</param>
 /// <returns>True if the two vectors are approximately equal; otherwise, False.</returns>
 public static bool ApproxEqual(ComplexD a, ComplexD b, double tolerance)
 {
     return
         (
         (System.Math.Abs(a.Real - b.Real) <= tolerance) &&
         (System.Math.Abs(a.Imaginary - b.Imaginary) <= tolerance)
         );
 }
Пример #5
0
        /// <summary>
        /// Multiplies two complex numbers and put the result in a third complex number.
        /// </summary>
        /// <param name="a">A <see cref="ComplexD"/> instance.</param>
        /// <param name="b">A <see cref="ComplexD"/> instance.</param>
        /// <param name="result">A <see cref="ComplexD"/> instance to hold the result.</param>
        public static void Multiply(ComplexD a, ComplexD b, ComplexD result)
        {
            // (x + yi)(u + vi) = (xu � yv) + (xv + yu)i.
            double x = a.Real, y = a.Imaginary;
            double u = b.Real, v = b.Imaginary;

            result.Real      = x * u - y * v;
            result.Imaginary = x * v + y * u;
        }
Пример #6
0
 /// <summary>
 /// Returns a value indicating whether this instance is equal to
 /// the specified object.
 /// </summary>
 /// <param name="obj">An object to compare to this instance.</param>
 /// <returns>True if <paramref name="obj"/> is a <see cref="ComplexD"/> and has the same values as this instance; otherwise, False.</returns>
 public override bool Equals(object obj)
 {
     if (obj is ComplexD)
     {
         ComplexD c = (ComplexD)obj;
         return((this.Real == c.Real) && (this.Imaginary == c.Imaginary));
     }
     return(false);
 }
Пример #7
0
        /// <summary>
        /// Converts the given object to the type of this converter, using the specified context and culture information.
        /// </summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that provides a format context.</param>
        /// <param name="culture">The <see cref="System.Globalization.CultureInfo"/> to use as the current culture. </param>
        /// <param name="value">The <see cref="Object"/> to convert.</param>
        /// <returns>An <see cref="Object"/> that represents the converted value.</returns>
        /// <exception cref="ParseException">Failed parsing from string.</exception>
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (value.GetType() == typeof(string))
            {
                return(ComplexD.Parse((string)value));
            }

            return(base.ConvertFrom(context, culture, value));
        }
Пример #8
0
 /// <summary>
 /// Divides a scalar by a complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
 public static ComplexD Divide(double s, ComplexD a)
 {
     if ((a.Real == 0) || (a.Imaginary == 0))
     {
         throw new DivideByZeroException();
     }
     return(new ComplexD(
                s / a.Real,
                s / a.Imaginary));
 }
Пример #9
0
        public static ComplexD Exp(ComplexD a)
        {
            ComplexD result = ComplexD.Zero;
            double   r      = System.Math.Exp(a.Real);

            result.Real      = r * System.Math.Cos(a.Imaginary);
            result.Imaginary = r * System.Math.Sin(a.Imaginary);

            return(result);
        }
Пример #10
0
 /// <summary>
 /// Divides a complex by a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
 public static ComplexD Divide(ComplexD a, double s)
 {
     if (s == 0)
     {
         throw new DivideByZeroException();
     }
     return(new ComplexD(
                a.Real / s,
                a.Imaginary / s));
 }
Пример #11
0
        /// <summary>
        /// Converts the given value object to the specified type, using the specified context and culture information.
        /// </summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that provides a format context.</param>
        /// <param name="culture">A <see cref="System.Globalization.CultureInfo"/> object. If a null reference (Nothing in Visual Basic) is passed, the current culture is assumed.</param>
        /// <param name="value">The <see cref="Object"/> to convert.</param>
        /// <param name="destinationType">The Type to convert the <paramref name="value"/> parameter to.</param>
        /// <returns>An <see cref="Object"/> that represents the converted value.</returns>
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            if ((destinationType == typeof(string)) && (value is ComplexD))
            {
                ComplexD c = (ComplexD)value;
                return(c.ToString());
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Пример #12
0
        /// <summary>
        /// Divides a complex by a scalar and put the result into another complex number.
        /// </summary>
        /// <param name="a">A <see cref="ComplexD"/> instance.</param>
        /// <param name="s">A scalar.</param>
        /// <param name="result">A <see cref="ComplexD"/> instance to hold the result.</param>
        public static void Divide(ComplexD a, double s, ComplexD result)
        {
            if (s == 0)
            {
                throw new DivideByZeroException();
            }

            result.Real      = a.Real / s;
            result.Imaginary = a.Imaginary / s;
        }
Пример #13
0
        /// <summary>
        /// Divides a scalar by a complex and put the result into another complex number.
        /// </summary>
        /// <param name="a">A <see cref="ComplexD"/> instance.</param>
        /// <param name="s">A scalar.</param>
        /// <param name="result">A <see cref="ComplexD"/> instance to hold the result.</param>
        public static void Divide(double s, ComplexD a, ComplexD result)
        {
            if ((a.Real == 0) || (a.Imaginary == 0))
            {
                throw new DivideByZeroException();
            }

            result.Real      = s / a.Real;
            result.Imaginary = s / a.Imaginary;
        }
Пример #14
0
        /// <summary>
        /// Divides a complex by a complex and put the result in a third complex number.
        /// </summary>
        /// <param name="a">A <see cref="ComplexD"/> instance.</param>
        /// <param name="b">A <see cref="ComplexD"/> instance.</param>
        /// <param name="result">A <see cref="ComplexD"/> instance to hold the result.</param>
        public static void Divide(ComplexD a, ComplexD b, ComplexD result)
        {
            double x = a.Real, y = a.Imaginary;
            double u = b.Real, v = b.Imaginary;
            double modulusSquared = u * u + v * v;

            if (modulusSquared == 0)
            {
                throw new DivideByZeroException();
            }

            double invModulusSquared = 1 / modulusSquared;

            result.Real      = (x * u + y * v) * invModulusSquared;
            result.Imaginary = (y * u - x * v) * invModulusSquared;
        }
Пример #15
0
        /// <summary>
        /// Divides a complex by a complex.
        /// </summary>
        /// <param name="a">A <see cref="ComplexD"/> instance.</param>
        /// <param name="b">A <see cref="ComplexD"/> instance.</param>
        /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
        public static ComplexD Divide(ComplexD a, ComplexD b)
        {
            double x = a.Real, y = a.Imaginary;
            double u = b.Real, v = b.Imaginary;
            double modulusSquared = u * u + v * v;

            if (modulusSquared == 0)
            {
                throw new DivideByZeroException();
            }

            double invModulusSquared = 1 / modulusSquared;

            return(new ComplexD(
                       (x * u + y * v) * invModulusSquared,
                       (y * u - x * v) * invModulusSquared));
        }
Пример #16
0
        public static ComplexD Cos(ComplexD a)
        {
            ComplexD result = ComplexD.Zero;

            if (a.Imaginary == 0.0)
            {
                result.Real      = System.Math.Cos(a.Real);
                result.Imaginary = 0.0;
            }
            else
            {
                result.Real      = System.Math.Cos(a.Real) * System.Math.Cosh(a.Imaginary);
                result.Imaginary = -System.Math.Sin(a.Real) * System.Math.Sinh(a.Imaginary);
            }

            return(result);
        }
Пример #17
0
        public static ComplexD Tan(ComplexD a)
        {
            ComplexD result = ComplexD.Zero;

            if (a.Imaginary == 0.0)
            {
                result.Real      = System.Math.Tan(a.Real);
                result.Imaginary = 0.0;
            }
            else
            {
                double real2 = 2 * a.Real;
                double imag2 = 2 * a.Imaginary;
                double denom = System.Math.Cos(real2) + System.Math.Cosh(real2);

                result.Real      = System.Math.Sin(real2) / denom;
                result.Imaginary = System.Math.Sinh(imag2) / denom;
            }

            return(result);
        }
Пример #18
0
		public static ComplexD Acot(ComplexD complex)
		{
			ComplexD tmp = new ComplexD(-complex.Imaginary, complex.Real);
			return (new ComplexD(0, 0.5)) * (ComplexD.Log(1 + tmp) - ComplexD.Log(1 - tmp)) + MathFunctions.HalfPI;
		}
Пример #19
0
		/// <summary>
		/// Calculates the hyperbolic cosine of the specified complex number. 
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <returns>Returns the hyperbolic cosine of the specified complex number.</returns>
		public static ComplexD Cosh(ComplexD complex)
		{
			if (complex.IsReal)
			{
				return new ComplexD(System.Math.Cosh(complex.Real), 0.0);
			}

			return new ComplexD(
				System.Math.Cosh(complex.Real) * System.Math.Cos(complex.Imaginary),
				System.Math.Sinh(complex.Real) * System.Math.Sin(complex.Imaginary)
				);
		}
Пример #20
0
		/// <summary>
		/// Calculates the cosecant of the specified complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <returns>The cosecant of <paramref name="complex"/>.</returns>
		public static ComplexD Csc(ComplexD complex)
		{
			ComplexD result = ComplexD.Zero;

			if (complex.IsReal)
			{
				result.Real = MathFunctions.Csc(complex.Real);
			}
			else
			{
				double sinr = MathFunctions.Sin(complex.Real);
				double sinhi = MathFunctions.Sinh(complex.Imaginary);
				double denom = sinr * sinr + sinhi * sinhi;
				result.Real = (sinr * MathFunctions.Cosh(complex.Imaginary)) / denom;
				result.Imaginary = (-MathFunctions.Cos(complex.Real) * sinhi) / denom;
			}

			return result;
		}
Пример #21
0
		public static ComplexD Acos(ComplexD complex)
		{
			ComplexD result = 1 - ComplexD.Square(complex);
			result = ComplexD.Sqrt(result);
			result = ComplexD.I * result;
			result = complex + result;
			result = ComplexD.Log(result);
			result = -ComplexD.I * result;
			return result;
		}
Пример #22
0
		/// <summary>
		/// Calculates a specified complex number raised by a specified power.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> representing the number to raise.</param>
		/// <param name="power">A <see cref="ComplexD"/> representing the power.</param>
		/// <returns>The complex <paramref name="complex"/> raised by <paramref name="power"/>.</returns>
		public static ComplexD Pow(ComplexD complex, ComplexD power)
		{
			return Exp(power * Log(complex));
		}
Пример #23
0
		/// <summary>
		/// Calculates the cosine of the specified complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <returns>The cosine of <paramref name="complex"/>.</returns>
		public static ComplexD Cos(ComplexD complex)
		{
			ComplexD result = ComplexD.Zero;

			if (complex.IsReal)
			{
				result.Real = System.Math.Cos(complex.Real);
				result.Imaginary = 0.0;
			}
			else
			{
				result.Real = System.Math.Cos(complex.Real) * System.Math.Cosh(complex.Imaginary);
				result.Imaginary = -System.Math.Sin(complex.Real) * System.Math.Sinh(complex.Imaginary);
			}

			return result;
		}
Пример #24
0
 /// <summary>
 /// Negates a complex number.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the negated values.</returns>
 public static ComplexD Negate(ComplexD a)
 {
     return(new ComplexD(-a.Real, -a.Imaginary));
 }
Пример #25
0
		/// <summary>
		/// Divides a complex by a complex and put the result in a third complex number.
		/// </summary>
		/// <param name="left">A <see cref="ComplexD"/> instance.</param>
		/// <param name="right">A <see cref="ComplexD"/> instance.</param>
		/// <param name="result">A <see cref="ComplexD"/> instance to hold the result.</param>
		/// <remarks>See http://mathworld.wolfram.com/ComplexDivision.html for further details.</remarks>
		public static void Divide(ComplexD left, ComplexD right, ref ComplexD result)
		{
			double x = left.Real, y = left.Imaginary;
			double u = right.Real, v = right.Imaginary;
			double modulusSquared = u * u + v * v;

			if (modulusSquared == 0)
			{
				throw new DivideByZeroException();
			}

			double invModulusSquared = 1 / modulusSquared;

			result.Real = (x * u + y * v) * invModulusSquared;
			result.Imaginary = (y * u - x * v) * invModulusSquared;
		}
Пример #26
0
		/// <summary>
		/// Divides a complex by a scalar.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <param name="scalar">A double-precision floating-point value.</param>
		/// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
		public static ComplexD Divide(ComplexD complex, double scalar)
		{
			if (scalar == 0)
			{
				throw new DivideByZeroException();
			}

			return new ComplexD(
				complex.Real / scalar,
				complex.Imaginary / scalar);
		}
Пример #27
0
 /// <summary>
 /// Tests whether two complex numbers are approximately equal using default tolerance value.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="b">A <see cref="ComplexD"/> instance.</param>
 /// <returns>True if the two vectors are approximately equal; otherwise, False.</returns>
 public static bool ApproxEqual(ComplexD a, ComplexD b)
 {
     return(ApproxEqual(a, b, MathFunctions.EpsilonD));
 }
Пример #28
0
		/// <summary>
		/// Calculates the hyperbolic cotangent of the specified complex number. 
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <returns>Returns the hyperbolic cotangent of the specified complex number.</returns>
		public static ComplexD Coth(ComplexD complex)
		{
			if (complex.IsReal)
			{
				return new ComplexD(MathFunctions.Coth(complex.Real), 0.0);
			}

			//return ComplexD.Divide(Cosh(complex), Sinh(complex));
			double sini = -System.Math.Sin(complex.Imaginary);
			double sinhr = System.Math.Sinh(complex.Real);
			double denom = (sini * sini) + (sinhr * sinhr);

			return new ComplexD(
				(sinhr * System.Math.Cosh(complex.Real)) / denom,
				(sini * System.Math.Cos(complex.Imaginary)) / denom
				);
		}
Пример #29
0
		public static ComplexD Asinh(ComplexD complex)
		{
			ComplexD result = ComplexD.Sqrt(ComplexD.Square(complex) + 1);
			result = ComplexD.Log(complex + result);
			return result;
		}
Пример #30
0
		/// <summary>
		/// Divides a scalar by a complex and put the result into another complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <param name="scalar">A double-precision floating-point value.</param>
		/// <param name="result">A <see cref="ComplexD"/> instance to hold the result.</param>
		public static void Divide(double scalar, ComplexD complex, ref ComplexD result)
		{
			if ((complex.Real == 0) || (complex.Imaginary == 0))
			{
				throw new DivideByZeroException();
			}

			result.Real = scalar / complex.Real;
			result.Imaginary = scalar / complex.Imaginary;
		}
Пример #31
0
		/// <summary>
		/// Divides a complex by a complex.
		/// </summary>
		/// <param name="left">A <see cref="ComplexD"/> instance.</param>
		/// <param name="right">A <see cref="ComplexD"/> instance.</param>
		/// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
		/// <remarks>See http://mathworld.wolfram.com/ComplexDivision.html for further details.</remarks>
		public static ComplexD Divide(ComplexD left, ComplexD right)
		{
			double x = left.Real, y = left.Imaginary;
			double u = right.Real, v = right.Imaginary;
			double modulusSquared = u * u + v * v;

			if (modulusSquared == 0)
			{
				throw new DivideByZeroException();
			}

			double invModulusSquared = 1 / modulusSquared;

			return new ComplexD(
				(x * u + y * v) * invModulusSquared,
				(y * u - x * v) * invModulusSquared);
		}
Пример #32
0
		/// <summary>
		/// Tests whether two complex numbers are approximately equal using default tolerance value.
		/// </summary>
		/// <param name="left">A <see cref="ComplexD"/> instance.</param>
		/// <param name="right">A <see cref="ComplexD"/> instance.</param>
		/// <returns><see langword="true"/> if the two vectors are approximately equal; otherwise, <see langword="false"/>.</returns>
		public static bool ApproxEqual(ComplexD left, ComplexD right)
		{
			return ApproxEqual(left, right, MathFunctions.EpsilonD);
		}
Пример #33
0
		/// <summary>
		/// Divides a scalar by a complex.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <param name="scalar">A double-precision floating-point value.</param>
		/// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
		public static ComplexD Divide(double scalar, ComplexD complex)
		{
			if ((complex.Real == 0) || (complex.Imaginary == 0))
			{
				throw new DivideByZeroException();
			}

			return new ComplexD(
				scalar / complex.Real,
				scalar / complex.Imaginary);
		}
Пример #34
0
		/// <summary>
		/// Calculates the square root of a complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <returns>The square root of the complex number given in <paramref name="complex"/>.</returns>
		/// <remarks>See http://mathworld.wolfram.com/SquareRoot.html for further details.</remarks>
		public static ComplexD Sqrt(ComplexD complex)
		{
			ComplexD result = ComplexD.Zero;

			if ((complex.Real == 0.0) && (complex.Imaginary == 0.0))
			{
				return result;
			}
			else if (complex.IsReal)
			{
				result.Real = (complex.Real > 0) ? System.Math.Sqrt(complex.Real) : System.Math.Sqrt(-complex.Real);
				result.Imaginary = 0.0;
			}
			else
			{
				double modulus = complex.Modulus;

				result.Real = System.Math.Sqrt(0.5 * (modulus + complex.Real));
				result.Imaginary = System.Math.Sqrt(0.5 * (modulus - complex.Real));
				if (complex.Imaginary < 0.0)
					result.Imaginary = -result.Imaginary;
			}

			return result;
		}
Пример #35
0
		/// <summary>
		/// Divides a complex by a scalar and put the result into another complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <param name="scalar">A double-precision floating-point value.</param>
		/// <param name="result">A <see cref="ComplexD"/> instance to hold the result.</param>
		public static void Divide(ComplexD complex, double scalar, ref ComplexD result)
		{
			if (scalar == 0)
			{
				throw new DivideByZeroException();
			}

			result.Real = complex.Real / scalar;
			result.Imaginary = complex.Imaginary / scalar;
		}
Пример #36
0
		/// <summary>
		/// Calculates the logarithm of a specified complex number.
		/// Calculates the natural (base e) logarithm of a specified complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <returns>The natural (base e) logarithm of the complex number given in <paramref name="complex"/>.</returns>
		public static ComplexD Log(ComplexD complex)
		{
			ComplexD result = ComplexD.Zero;

			if ((complex.Real > 0.0) && (complex.Imaginary == 0.0))
			{
				result.Real = System.Math.Log(complex.Real);
				result.Imaginary = 0.0;
			}
			else if (complex.Real == 0.0)
			{
				if (complex.Imaginary > 0.0)
				{
					result.Real = System.Math.Log(complex.Imaginary);
					result.Imaginary = MathFunctions.HalfPI;
				}
				else
				{
					result.Real = System.Math.Log(-(complex.Imaginary));
					result.Imaginary = -MathFunctions.HalfPI;
				}
			}
			else
			{
				result.Real = System.Math.Log(complex.Modulus);
				result.Imaginary = System.Math.Atan2(complex.Imaginary, complex.Real);
			}

			return result;
		}
Пример #37
0
		/// <summary>
		/// Negates a complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <returns>A new <see cref="ComplexD"/> instance containing the negated values.</returns>
		public static ComplexD Negate(ComplexD complex)
		{
			return new ComplexD(-complex.Real, -complex.Imaginary);
		}
Пример #38
0
 /// <summary>
 /// Negates the complex number.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the negated values.</returns>
 public static ComplexD operator -(ComplexD a)
 {
     return(ComplexD.Negate(a));
 }
Пример #39
0
		/// <summary>
		/// Tests whether two complex numbers are approximately equal given a tolerance value.
		/// </summary>
		/// <param name="left">A <see cref="ComplexD"/> instance.</param>
		/// <param name="right">A <see cref="ComplexD"/> instance.</param>
		/// <param name="tolerance">The tolerance value used to test approximate equality.</param>
		/// <returns><see langword="true"/> if the two vectors are approximately equal; otherwise, <see langword="false"/>.</returns>
		public static bool ApproxEqual(ComplexD left, ComplexD right, double tolerance)
		{
			return
				(
				(System.Math.Abs(left.Real - right.Real) <= tolerance) &&
				(System.Math.Abs(left.Imaginary - right.Imaginary) <= tolerance)
				);
		}
Пример #40
0
 /// <summary>
 /// Adds two complex numbers.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="b">A <see cref="ComplexD"/> instance.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the sum.</returns>
 public static ComplexD operator +(ComplexD a, ComplexD b)
 {
     return(ComplexD.Add(a, b));
 }
Пример #41
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ComplexD"/> class using values from a given complex instance.
		/// </summary>
		/// <param name="c">A complex number to get values from.</param>
		public ComplexD(ComplexD c)
		{
			_real = c.Real;
			_image = c.Imaginary;
		}
Пример #42
0
 /// <summary>
 /// Adds a complex number and a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the sum.</returns>
 public static ComplexD operator +(double s, ComplexD a)
 {
     return(ComplexD.Add(a, s));
 }
Пример #43
0
		/// <summary>
		/// Calculates the exponential of a specified complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <returns>The exponential of the complex number given in <paramref name="complex"/>.</returns>
		public static ComplexD Exp(ComplexD complex)
		{
			ComplexD result = ComplexD.Zero;
			double r = System.Math.Exp(complex.Real);
			result.Real = r * System.Math.Cos(complex.Imaginary);
			result.Imaginary = r * System.Math.Sin(complex.Imaginary);

			return result;
		}
Пример #44
0
 /// <summary>
 /// Subtracts a complex from a complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="b">A <see cref="ComplexD"/> instance.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the difference.</returns>
 public static ComplexD operator -(ComplexD a, ComplexD b)
 {
     return(ComplexD.Subtract(a, b));
 }
Пример #45
0
		/// <summary>
		/// Calculates the square of the specified complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <returns>The square of the given complex number.</returns>
		public static ComplexD Square(ComplexD complex)
		{
			if (complex.IsReal)
			{
				return new ComplexD(complex.Real * complex.Real, 0.0);
			}

			double real = complex.Real;
			double imag = complex.Imaginary;
			return new ComplexD(real * real - imag * imag, 2 * real * imag);
		}
Пример #46
0
 /// <summary>
 /// Subtracts a scalar from a complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the difference.</returns>
 public static ComplexD operator -(ComplexD a, double s)
 {
     return(ComplexD.Subtract(a, s));
 }
Пример #47
0
		/// <summary>
		/// Calculates the tangent of the specified complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <returns>The tangent of <paramref name="complex"/>.</returns>
		public static ComplexD Tan(ComplexD complex)
		{
			ComplexD result = ComplexD.Zero;

			if (complex.IsReal)
			{
				result.Real = System.Math.Tan(complex.Real);
				result.Imaginary = 0.0;
			}
			else
			{
				double cosr = System.Math.Cos(complex.Real);
				double sinhi = System.Math.Sinh(complex.Imaginary);
				double denom = cosr * cosr + sinhi * sinhi;

				result.Real = System.Math.Sin(complex.Real) * cosr / denom;
				result.Imaginary = sinhi * System.Math.Cosh(complex.Imaginary) / denom;
			}

			return result;
		}
Пример #48
0
 /// <summary>
 /// Subtracts a complex from a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the difference.</returns>
 public static ComplexD operator -(double s, ComplexD a)
 {
     return(ComplexD.Subtract(s, a));
 }
Пример #49
0
		public static ComplexD Asin(ComplexD complex)
		{
			ComplexD result = 1 - ComplexD.Square(complex);
			result = ComplexD.Sqrt(result);
			result = result + (ComplexD.I * complex);
			result = ComplexD.Log(result);
			result = -ComplexD.I * result;

			return result;
		}
Пример #50
0
 /// <summary>
 /// Multiplies two complex numbers.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="b">A <see cref="ComplexD"/> instance.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
 public static ComplexD operator *(ComplexD a, ComplexD b)
 {
     return(ComplexD.Multiply(a, b));
 }
Пример #51
0
		public static ComplexD Atan(ComplexD complex)
		{
			ComplexD tmp = new ComplexD(-complex.Imaginary, complex.Real);
			return (new ComplexD(0, 0.5)) * (ComplexD.Log(1 - tmp) - ComplexD.Log(1 + tmp));
		}
Пример #52
0
 /// <summary>
 /// Multiplies a complex by a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
 public static ComplexD operator *(ComplexD a, double s)
 {
     return(ComplexD.Multiply(a, s));
 }
Пример #53
0
		public static ComplexD Acsc(ComplexD complex)
		{
			ComplexD inverse = 1 / complex;
			return (-ComplexD.I) * ComplexD.Log(ComplexD.I * inverse + ComplexD.Sqrt(1 - ComplexD.Square(inverse)));
		}
Пример #54
0
 /// <summary>
 /// Divides a complex by a complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="b">A <see cref="ComplexD"/> instance.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
 public static ComplexD operator /(ComplexD a, ComplexD b)
 {
     return(ComplexD.Divide(a, b));
 }
Пример #55
0
		/// <summary>
		/// Calculates the hyperbolic tangent of the specified complex number. 
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <returns>Returns the hyperbolic tangent of the specified complex number.</returns>
		public static ComplexD Tanh(ComplexD complex)
		{
			if (complex.IsReal)
			{
				return new ComplexD(System.Math.Tanh(complex.Real), 0.0);
			}

			double cosi = System.Math.Cos(complex.Imaginary);
			double sinhr = System.Math.Sinh(complex.Real);
			double denom = (cosi * cosi) + (sinhr * sinhr);

			return new ComplexD(
				(sinhr* System.Math.Cosh(complex.Real)) / denom,
				(cosi * System.Math.Sin(complex.Imaginary)) / denom
				);
		}
Пример #56
0
 /// <summary>
 /// Divides a complex by a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
 public static ComplexD operator /(ComplexD a, double s)
 {
     return(ComplexD.Divide(a, s));
 }
Пример #57
0
		/// <summary>
		/// Calculates the hyperbolic cosecant of the specified complex number. 
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <returns>Returns the hyperbolic cosecant of the specified complex number.</returns>
		public static ComplexD Csch(ComplexD complex)
		{
			if (complex.IsReal)
			{
				return new ComplexD(MathFunctions.Csch(complex.Real), 0.0);
			}

			ComplexD exp = ComplexD.Exp(complex);
			return (2 * exp) / (ComplexD.Square(exp) - 1);
		}
Пример #58
0
 /// <summary>
 /// Divides a scalar by a complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexD"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexD"/> instance containing the result.</returns>
 public static ComplexD operator /(double s, ComplexD a)
 {
     return(ComplexD.Divide(s, a));
 }
Пример #59
0
		public static ComplexD Acosh(ComplexD complex)
		{
			ComplexD result = ComplexD.Sqrt(complex - 1) * ComplexD.Sqrt(complex + 1);
			result = complex + result;
			result = ComplexD.Log(result);
			return result;
		}
Пример #60
0
		/// <summary>
		/// Multiplies a complex by a scalar and put the result into another complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexD"/> instance.</param>
		/// <param name="scalar">A double-precision floating-point value.</param>
		/// <param name="result">A <see cref="ComplexD"/> instance to hold the result.</param>
		public static void Multiply(ComplexD complex, double scalar, ref ComplexD result)
		{
			result.Real = complex.Real * scalar;
			result.Imaginary = complex.Imaginary * scalar;
		}