Esempio n. 1
0
		/// <summary>
		/// Divides a complex by a complex and put the result in a third complex number.
		/// </summary>
		/// <param name="left">A <see cref="ComplexF"/> instance.</param>
		/// <param name="right">A <see cref="ComplexF"/> instance.</param>
		/// <param name="result">A <see cref="ComplexF"/> instance to hold the result.</param>
		/// <remarks>See http://mathworld.wolfram.com/ComplexFivision.html for further details.</remarks>
		public static void Divide(ComplexF left, ComplexF right, ref ComplexF result)
		{
			float x = left.Real, y = left.Imaginary;
			float u = right.Real, v = right.Imaginary;
			float modulusSquared = u * u + v * v;

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

			float invModulusSquared = 1 / modulusSquared;

			result.Real = (x * u + y * v) * invModulusSquared;
			result.Imaginary = (y * u - x * v) * invModulusSquared;
		}
Esempio n. 2
0
		/// <summary>
		/// Calculates the hyperbolic cotangent of the specified complex number. 
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> instance.</param>
		/// <returns>Returns the hyperbolic cotangent of the specified complex number.</returns>
		public static ComplexF Coth(ComplexF complex)
		{
			if (complex.IsReal)
			{
				return new ComplexF((float)MathFunctions.Coth(complex.Real), 0.0f);
			}

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

			return new ComplexF(
				(sinhr * (float)System.Math.Cosh(complex.Real)) / denom,
				(sini * (float)System.Math.Cos(complex.Imaginary)) / denom
				);
		}
Esempio n. 3
0
 /// <summary>
 /// Subtracts a complex from a complex and put the result in the third complex number.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="b">A <see cref="ComplexF"/> instance.</param>
 /// <param name="result">A <see cref="ComplexF"/> instance to hold the result.</param>
 public static void Subtract(ComplexF a, ComplexF b, ref ComplexF result)
 {
     result.Real      = a.Real - b.Real;
     result.Imaginary = a.Imaginary - b.Imaginary;
 }
Esempio n. 4
0
		/// <summary>
		/// Calculates the cosecant of the specified complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> instance.</param>
		/// <returns>The cosecant of <paramref name="complex"/>.</returns>
		public static ComplexF Csc(ComplexF complex)
		{
			ComplexF result = ComplexF.Zero;

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

			return result;
		}
Esempio n. 5
0
		public static ComplexF Acot(ComplexF complex)
		{
			ComplexF tmp = new ComplexF(-complex.Imaginary, complex.Real);
			return (new ComplexF(0.0f, 0.5f)) * (ComplexF.Log(1.0f + tmp) - ComplexF.Log(1.0f - tmp)) + (float)MathFunctions.HalfPI;
		}
Esempio n. 6
0
		/// <summary>
		/// Calculates the square root of a complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> 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 ComplexF Sqrt(ComplexF complex)
		{
			ComplexF result = ComplexF.Zero;

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

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

			return result;
		}
Esempio n. 7
0
		/// <summary>
		/// Calculates a specified complex number raised by a specified power.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> representing the number to raise.</param>
		/// <param name="power">A <see cref="ComplexF"/> representing the power.</param>
		/// <returns>The complex <paramref name="complex"/> raised by <paramref name="power"/>.</returns>
		public static ComplexF Pow(ComplexF complex, ComplexF power)
		{
			return Exp(power * Log(complex));
		}
Esempio n. 8
0
 /// <summary>
 /// Tests whether two complex numbers are approximately equal using default tolerance value.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="b">A <see cref="ComplexF"/> instance.</param>
 /// <returns><see langword="true"/> if the two vectors are approximately equal; otherwise, <see langword="false"/>.</returns>
 public static bool ApproxEqual(ComplexF a, ComplexF b)
 {
     return(ApproxEqual(a, b, MathFunctions.EpsilonF));
 }
Esempio n. 9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ComplexF"/> class using values from a given complex instance.
 /// </summary>
 /// <param name="c">A complex number to get values from.</param>
 public ComplexF(ComplexF c)
 {
     _real  = c.Real;
     _image = c.Imaginary;
 }
Esempio n. 10
0
 /// <summary>
 /// Multiplies a complex by a scalar and put the result into another complex number.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <param name="result">A <see cref="ComplexF"/> instance to hold the result.</param>
 public static void Multiply(float s, ComplexF a, ref ComplexF result)
 {
     result.Real      = a.Real * s;
     result.Imaginary = a.Imaginary * s;
 }
Esempio n. 11
0
 /// <summary>
 /// Negates a complex number.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the negated values.</returns>
 public static ComplexF Negate(ComplexF a)
 {
     return(new ComplexF(-a.Real, -a.Imaginary));
 }
Esempio n. 12
0
 /// <summary>
 /// Multiplies a complex by a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the result.</returns>
 public static ComplexF Multiply(float s, ComplexF a)
 {
     return(new ComplexF(a.Real * s, a.Imaginary * s));
 }
Esempio n. 13
0
 /// <summary>
 /// Subtracts a complex from a scalar and put the result into another complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <param name="result">A <see cref="ComplexF"/> instance to hold the result.</param>
 public static void Subtract(float s, ComplexF a, ref ComplexF result)
 {
     result.Real      = s - a.Real;
     result.Imaginary = a.Imaginary;
 }
Esempio n. 14
0
 /// <summary>
 /// Subtracts a scalar from a complex and put the result into another complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <param name="result">A <see cref="ComplexF"/> instance to hold the result.</param>
 public static void Subtract(ComplexF a, float s, ref ComplexF result)
 {
     result.Real      = a.Real - s;
     result.Imaginary = a.Imaginary;
 }
Esempio n. 15
0
		/// <summary>
		/// Divides a scalar by a complex and put the result into another complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> instance.</param>
		/// <param name="scalar">A single-precision floating-point value.</param>
		/// <param name="result">A <see cref="ComplexF"/> instance to hold the result.</param>
		public static void Divide(float scalar, ComplexF complex, ref ComplexF result)
		{
			if ((complex.Real == 0) || (complex.Imaginary == 0))
			{
				throw new DivideByZeroException();
			}

			result.Real = scalar / complex.Real;
			result.Imaginary = scalar / complex.Imaginary;
		}
Esempio n. 16
0
 /// <summary>
 /// Negates the complex number.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the negated values.</returns>
 public static ComplexF operator-(ComplexF a)
 {
     return(ComplexF.Negate(a));
 }
Esempio n. 17
0
		/// <summary>
		/// Tests whether two complex numbers are approximately equal using default tolerance value.
		/// </summary>
		/// <param name="left">A <see cref="ComplexF"/> instance.</param>
		/// <param name="right">A <see cref="ComplexF"/> instance.</param>
		/// <returns><see langword="true"/> if the two vectors are approximately equal; otherwise, <see langword="false"/>.</returns>
		public static bool ApproxEqual(ComplexF left, ComplexF right)
		{
			return ApproxEqual(left, right, MathFunctions.EpsilonF);
		}
Esempio n. 18
0
 /// <summary>
 /// Adds two complex numbers.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="b">A <see cref="ComplexF"/> instance.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the sum.</returns>
 public static ComplexF operator+(ComplexF a, ComplexF b)
 {
     return(ComplexF.Add(a, b));
 }
Esempio n. 19
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="ComplexF"/> instance.</param>
		/// <returns>The natural (base e) logarithm of the complex number given in <paramref name="complex"/>.</returns>
		public static ComplexF Log(ComplexF complex)
		{
			ComplexF result = ComplexF.Zero;

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

			return result;
		}
Esempio n. 20
0
 /// <summary>
 /// Adds a complex number and a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the sum.</returns>
 public static ComplexF operator+(float s, ComplexF a)
 {
     return(ComplexF.Add(a, s));
 }
Esempio n. 21
0
		/// <summary>
		/// Calculates the cosine of the specified complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> instance.</param>
		/// <returns>The cosine of <paramref name="complex"/>.</returns>
		public static ComplexF Cos(ComplexF complex)
		{
			ComplexF result = ComplexF.Zero;

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

			return result;
		}
Esempio n. 22
0
 /// <summary>
 /// Subtracts a complex from a complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="b">A <see cref="ComplexF"/> instance.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the difference.</returns>
 public static ComplexF operator-(ComplexF a, ComplexF b)
 {
     return(ComplexF.Subtract(a, b));
 }
Esempio n. 23
0
		public static ComplexF Acos(ComplexF complex)
		{
			ComplexF result = 1 - ComplexF.Square(complex);
			result = ComplexF.Sqrt(result);
			result = ComplexF.I * result;
			result = complex + result;
			result = ComplexF.Log(result);
			result = -ComplexF.I * result;
			return result;
		}
Esempio n. 24
0
 /// <summary>
 /// Subtracts a scalar from a complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the difference.</returns>
 public static ComplexF operator-(ComplexF a, float s)
 {
     return(ComplexF.Subtract(a, s));
 }
Esempio n. 25
0
		/// <summary>
		/// Calculates the hyperbolic cosine of the specified complex number. 
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> instance.</param>
		/// <returns>Returns the hyperbolic cosine of the specified complex number.</returns>
		public static ComplexF Cosh(ComplexF complex)
		{
			if (complex.IsReal)
			{
				return new ComplexF((float)System.Math.Cosh(complex.Real), 0.0f);
			}

			return new ComplexF(
				(float)(System.Math.Cosh(complex.Real) * System.Math.Cos(complex.Imaginary)),
				(float)(System.Math.Sinh(complex.Real) * System.Math.Sin(complex.Imaginary))
				);
		}
Esempio n. 26
0
 /// <summary>
 /// Subtracts a complex from a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the difference.</returns>
 public static ComplexF operator-(float s, ComplexF a)
 {
     return(ComplexF.Subtract(s, a));
 }
Esempio n. 27
0
		public static ComplexF Asinh(ComplexF complex)
		{
			ComplexF result = ComplexF.Sqrt(ComplexF.Square(complex) + 1);
			result = ComplexF.Log(complex + result);
			return result;
		}
Esempio n. 28
0
 /// <summary>
 /// Multiplies two complex numbers.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="b">A <see cref="ComplexF"/> instance.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the result.</returns>
 public static ComplexF operator*(ComplexF a, ComplexF b)
 {
     return(ComplexF.Multiply(a, b));
 }
Esempio n. 29
0
		/// <summary>
		/// Divides a scalar by a complex.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> instance.</param>
		/// <param name="scalar">A single-precision floating-point value.</param>
		/// <returns>A new <see cref="ComplexF"/> instance containing the result.</returns>
		public static ComplexF Divide(float scalar, ComplexF complex)
		{
			if ((complex.Real == 0) || (complex.Imaginary == 0))
			{
				throw new DivideByZeroException();
			}

			return new ComplexF(
				scalar / complex.Real,
				scalar / complex.Imaginary);
		}
Esempio n. 30
0
 /// <summary>
 /// Multiplies a complex by a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the result.</returns>
 public static ComplexF operator*(ComplexF a, float s)
 {
     return(ComplexF.Multiply(a, s));
 }
Esempio n. 31
0
		/// <summary>
		/// Divides a complex by a scalar and put the result into another complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> instance.</param>
		/// <param name="scalar">A single-precision floating-point value.</param>
		/// <param name="result">A <see cref="ComplexF"/> instance to hold the result.</param>
		public static void Divide(ComplexF complex, float scalar, ref ComplexF result)
		{
			if (scalar == 0)
			{
				throw new DivideByZeroException();
			}

			result.Real = complex.Real / scalar;
			result.Imaginary = complex.Imaginary / scalar;
		}
Esempio n. 32
0
 /// <summary>
 /// Divides a complex by a complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="b">A <see cref="ComplexF"/> instance.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the result.</returns>
 public static ComplexF operator/(ComplexF a, ComplexF b)
 {
     return(ComplexF.Divide(a, b));
 }
Esempio n. 33
0
		/// <summary>
		/// Negates a complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> instance.</param>
		/// <returns>A new <see cref="ComplexF"/> instance containing the negated values.</returns>
		public static ComplexF Negate(ComplexF complex)
		{
			return new ComplexF(-complex.Real, -complex.Imaginary);
		}
Esempio n. 34
0
 /// <summary>
 /// Divides a complex by a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the result.</returns>
 public static ComplexF operator/(ComplexF a, float s)
 {
     return(ComplexF.Divide(a, s));
 }
Esempio n. 35
0
		/// <summary>
		/// Tests whether two complex numbers are approximately equal given a tolerance value.
		/// </summary>
		/// <param name="left">A <see cref="ComplexF"/> instance.</param>
		/// <param name="right">A <see cref="ComplexF"/> 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(ComplexF left, ComplexF right, float tolerance)
		{
			return
				(
				(System.Math.Abs(left.Real - right.Real) <= tolerance) &&
				(System.Math.Abs(left.Imaginary - right.Imaginary) <= tolerance)
				);
		}
Esempio n. 36
0
 /// <summary>
 /// Divides a scalar by a complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the result.</returns>
 public static ComplexF operator/(float s, ComplexF a)
 {
     return(ComplexF.Divide(s, a));
 }
Esempio n. 37
0
		/// <summary>
		/// Initializes a new instance of the <see cref="ComplexF"/> class using values from a given complex instance.
		/// </summary>
		/// <param name="c">A complex number to get values from.</param>
		public ComplexF(ComplexF c)
		{
			_real = c.Real;
			_image = c.Imaginary;
		}
Esempio n. 38
0
 /// <summary>
 /// Adds two complex numbers.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="b">A <see cref="ComplexF"/> instance.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the sum.</returns>
 public static ComplexF Add(ComplexF a, ComplexF b)
 {
     return(new ComplexF(a.Real + b.Real, a.Imaginary + b.Imaginary));
 }
Esempio n. 39
0
		/// <summary>
		/// Calculates the exponential of a specified complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> instance.</param>
		/// <returns>The exponential of the complex number given in <paramref name="complex"/>.</returns>
		public static ComplexF Exp(ComplexF complex)
		{
			ComplexF result = ComplexF.Zero;
			float r = (float)System.Math.Exp(complex.Real);
			result.Real = r * (float)System.Math.Cos(complex.Imaginary);
			result.Imaginary = r * (float)System.Math.Sin(complex.Imaginary);

			return result;
		}
Esempio n. 40
0
 /// <summary>
 /// Adds a complex number and a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the sum.</returns>
 public static ComplexF Add(ComplexF a, float s)
 {
     return(new ComplexF(a.Real + s, a.Imaginary));
 }
Esempio n. 41
0
		/// <summary>
		/// Calculates the square of the specified complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> instance.</param>
		/// <returns>The square of the given complex number.</returns>
		public static ComplexF Square(ComplexF complex)
		{
			if (complex.IsReal)
			{
				return new ComplexF(complex.Real * complex.Real, 0.0f);
			}

			float real = complex.Real;
			float imag = complex.Imaginary;
			return new ComplexF(real * real - imag * imag, 2.0f * real * imag);
		}
Esempio n. 42
0
 /// <summary>
 /// Adds two complex numbers and put the result in the third complex number.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="b">A <see cref="ComplexF"/> instance.</param>
 /// <param name="result">A <see cref="ComplexF"/> instance to hold the result.</param>
 public static void Add(ComplexF a, ComplexF b, ComplexF result)
 {
     result.Real      = a.Real + b.Real;
     result.Imaginary = a.Imaginary + b.Imaginary;
 }
Esempio n. 43
0
		/// <summary>
		/// Calculates the tangent of the specified complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> instance.</param>
		/// <returns>The tangent of <paramref name="complex"/>.</returns>
		public static ComplexF Tan(ComplexF complex)
		{
			ComplexF result = ComplexF.Zero;

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

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

			return result;
		}
Esempio n. 44
0
 /// <summary>
 /// Adds a complex number and a scalar and put the result into another complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <param name="result">A <see cref="ComplexF"/> instance to hold the result.</param>
 public static void Add(ComplexF a, float s, ComplexF result)
 {
     result.Real      = a.Real + s;
     result.Imaginary = a.Imaginary;
 }
Esempio n. 45
0
		public static ComplexF Asin(ComplexF complex)
		{
			ComplexF result = 1 - ComplexF.Square(complex);
			result = ComplexF.Sqrt(result);
			result = result + (ComplexF.I * complex);
			result = ComplexF.Log(result);
			result = -ComplexF.I * result;

			return result;
		}
Esempio n. 46
0
 /// <summary>
 /// Subtracts a complex from a complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="b">A <see cref="ComplexF"/> instance.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the difference.</returns>
 public static ComplexF Subtract(ComplexF a, ComplexF b)
 {
     return(new ComplexF(a.Real - b.Real, a.Imaginary - b.Imaginary));
 }
Esempio n. 47
0
		public static ComplexF Atan(ComplexF complex)
		{
			ComplexF tmp = new ComplexF(-complex.Imaginary, complex.Real);
			return (new ComplexF(0.0f, 0.5f)) * (ComplexF.Log(1.0f - tmp) - ComplexF.Log(1.0f + tmp));
		}
Esempio n. 48
0
 /// <summary>
 /// Subtracts a scalar from a complex.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the difference.</returns>
 public static ComplexF Subtract(ComplexF a, float s)
 {
     return(new ComplexF(a.Real - s, a.Imaginary));
 }
Esempio n. 49
0
		public static ComplexF Acsc(ComplexF complex)
		{
			ComplexF inverse = 1 / complex;
			return (-ComplexF.I) * ComplexF.Log(ComplexF.I * inverse + ComplexF.Sqrt(1 - ComplexF.Square(inverse)));
		}
Esempio n. 50
0
		/// <summary>
		/// Multiplies a complex by a scalar and put the result into another complex number.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> instance.</param>
		/// <param name="scalar">A single-precision floating-point value.</param>
		/// <param name="result">A <see cref="ComplexF"/> instance to hold the result.</param>
		public static void Multiply(ComplexF complex, float scalar, ref ComplexF result)
		{
			result.Real = complex.Real * scalar;
			result.Imaginary = complex.Imaginary * scalar;
		}
Esempio n. 51
0
		/// <summary>
		/// Calculates the hyperbolic tangent of the specified complex number. 
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> instance.</param>
		/// <returns>Returns the hyperbolic tangent of the specified complex number.</returns>
		public static ComplexF Tanh(ComplexF complex)
		{
			if (complex.IsReal)
			{
				return new ComplexF((float)System.Math.Tanh(complex.Real), 0.0f);
			}

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

			return new ComplexF(
				(sinhr * (float)System.Math.Cosh(complex.Real)) / denom,
				(cosi * (float)System.Math.Sin(complex.Imaginary)) / denom
				);
		}
Esempio n. 52
0
		/// <summary>
		/// Divides a complex by a complex.
		/// </summary>
		/// <param name="left">A <see cref="ComplexF"/> instance.</param>
		/// <param name="right">A <see cref="ComplexF"/> instance.</param>
		/// <returns>A new <see cref="ComplexF"/> instance containing the result.</returns>
		/// <remarks>See http://mathworld.wolfram.com/ComplexFivision.html for further details.</remarks>
		public static ComplexF Divide(ComplexF left, ComplexF right)
		{
			float x = left.Real, y = left.Imaginary;
			float u = right.Real, v = right.Imaginary;
			float modulusSquared = u * u + v * v;

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

			float invModulusSquared = 1 / modulusSquared;

			return new ComplexF(
				(x * u + y * v) * invModulusSquared,
				(y * u - x * v) * invModulusSquared);
		}
Esempio n. 53
0
		/// <summary>
		/// Calculates the hyperbolic cosecant of the specified complex number. 
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> instance.</param>
		/// <returns>Returns the hyperbolic cosecant of the specified complex number.</returns>
		public static ComplexF Csch(ComplexF complex)
		{
			if (complex.IsReal)
			{
				return new ComplexF((float)MathFunctions.Csch((double)complex.Real), 0.0f);
			}

			ComplexF exp = ComplexF.Exp(complex);
			return (2 * exp) / (ComplexF.Square(exp) - 1);
		}
Esempio n. 54
0
		/// <summary>
		/// Divides a complex by a scalar.
		/// </summary>
		/// <param name="complex">A <see cref="ComplexF"/> instance.</param>
		/// <param name="scalar">A single-precision floating-point value.</param>
		/// <returns>A new <see cref="ComplexF"/> instance containing the result.</returns>
		public static ComplexF Divide(ComplexF complex, float scalar)
		{
			if (scalar == 0)
			{
				throw new DivideByZeroException();
			}

			return new ComplexF(
				complex.Real / scalar,
				complex.Imaginary / scalar);
		}
Esempio n. 55
0
		public static ComplexF Acosh(ComplexF complex)
		{
			ComplexF result = ComplexF.Sqrt(complex - 1) * ComplexF.Sqrt(complex + 1);
			result = complex + result;
			result = ComplexF.Log(result);
			return result;
		}
Esempio n. 56
0
 /// <summary>
 /// Subtracts a complex from a scalar.
 /// </summary>
 /// <param name="a">A <see cref="ComplexF"/> instance.</param>
 /// <param name="s">A scalar.</param>
 /// <returns>A new <see cref="ComplexF"/> instance containing the difference.</returns>
 public static ComplexF Subtract(float s, ComplexF a)
 {
     return(new ComplexF(s - a.Real, a.Imaginary));
 }