Complex.Abs(Complex) Metod

Definition

Hämtar det absoluta värdet (eller storleken) för ett komplext tal.

public:
 static double Abs(System::Numerics::Complex value);
public static double Abs(System.Numerics.Complex value);
static member Abs : System.Numerics.Complex -> double
Public Shared Function Abs (value As Complex) As Double

Parametrar

value
Complex

Ett komplext tal.

Returer

Det absoluta värdet för value.

Exempel

I följande exempel beräknas det absoluta värdet för ett komplext tal och visar att det motsvarar värdet för Magnitude egenskapen.

using System;
using System.Numerics;

public class Example
{
   public static void Main()
   {
      Complex complex1 = new Complex(2.0, 3.0);
      Console.WriteLine("|{0}| = {1:N2}", complex1, Complex.Abs(complex1));
      Console.WriteLine("Equal to Magnitude: {0}",
                        Complex.Abs(complex1).Equals(complex1.Magnitude));
   }
}
// The example displays the following output:
//       |(2, 3)| = 3.61
//       Equal to Magnitude: True
open System.Numerics

let complex1 = Complex(2., 3.)
printfn $"|{complex1}| = {Complex.Abs complex1:N2}"
printfn $"Equal to Magnitude: {Complex.Abs(complex1).Equals complex1.Magnitude}"
// The example displays the following output:
//       |(2, 3)| = 3.61
//       Equal to Magnitude: True

Kommentarer

Det absoluta värdet för ett komplext tal motsvarar dess Magnitude egenskap. Det absoluta värdet för ett komplext tal a + bi beräknas på följande sätt:

  • Om b = 0blir aresultatet .
  • Om a > bblir resultatet $a \times \sqrt{1 + \frac{b^2}{a^2}}$.
  • Om b > ablir resultatet $b \times \sqrt{1 + \frac{a^2}{b^2}}$.

Om beräkningen av det absoluta värdet resulterar i ett spill returnerar metoden antingen Double.PositiveInfinity eller Double.NegativeInfinity. Om antingen Real egenskapen eller Imaginary är Double.NaN och den andra egenskapen varken Double.PositiveInfinity är eller Double.NegativeInfinityreturnerar Double.NaNmetoden .

Gäller för

Se även