Complex.Magnitude 属性

定义

获取复数的量值(或绝对值)。Gets the magnitude (or absolute value) of a complex number.

public:
 property double Magnitude { double get(); };
public double Magnitude { get; }
member this.Magnitude : double
Public ReadOnly Property Magnitude As Double

属性值

当前实例的量值。The magnitude of the current instance.

示例

下面的示例计算复数的绝对值,并说明它等效于 Magnitude 属性的值。The following example calculates the absolute value of a complex number and demonstrates that it is equivalent to the value of the Magnitude property.

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.60555127546399
//       Equal to Magnitude: True
Imports System.Numerics

Module Example
   Public Sub Main()
      Dim complex1 As 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)) 
   End Sub
End Module
' The example displays the following output:
'       |(2, 3)| = 3.61
'       Equal to Magnitude: True

注解

Magnitude 属性等效于复数的绝对值。The Magnitude property is equivalent to the absolute value of a complex number. 它指定从原点(笛卡尔坐标系统中的 x 轴和 y 轴的交点)到复数表示的二维点之间的距离。It specifies the distance from the origin (the intersection of the x-axis and the y-axis in the Cartesian coordinate system) to the two-dimensional point represented by a complex number. 计算绝对值的方法如下:The absolute value is calculated as follows:

|a + bi | = Math.Sqrt(a * a + b * b)| a + bi | = Math.Sqrt(a * a + b * b)

如果绝对值的计算导致溢出,则此属性将返回 Double.PositiveInfinityDouble.NegativeInfinityIf the calculation of the absolute value results in an overflow, this property returns either Double.PositiveInfinity or Double.NegativeInfinity.

MagnitudePhase 属性定义表示极坐标系统中的复数的点的位置。The Magnitude and the Phase properties define the position of a point that represents a complex number in the polar coordinate system.

可以通过调用 FromPolarCoordinates 方法,基于其极坐标而不是笛卡尔坐标来实例化复数。You can instantiate a complex number based on its polar coordinates instead of its Cartesian coordinates by calling the FromPolarCoordinates method.

适用于

另请参阅