Complex class
A Dart representation of a complex number in the form a + bi
where a
is
the real part and bi
is the imaginary (or complex) part.
New instances of Complex can be created either by:
- using one of the constructors
- the extension method on num
A Complex object is immutable.
- Implemented types
Constructors
- Complex.new(double real, double imaginary)
-
Creates a complex number with the given real and imaginary parts.
const
- Complex.fromFraction(Fraction real, Fraction imaginary)
- Creates a complex number from Fraction objects as parameter for the real and imaginary part.
- Complex.fromImaginary(double imaginary)
-
Creates a complex number having only the imaginary part, meaning that the
real part is set to 0.
const
- Complex.fromImaginaryFraction(Fraction imaginary)
- Creates a complex number having only the imaginary part, which is expressed as a Fraction. The real part is set to 0.
- Complex.fromImaginaryMixedFraction(MixedFraction imaginary)
- Creates a complex number having only the imaginary part, which is expressed as a MixedFraction. The real part is set to 0.
- Complex.fromMixedFraction(MixedFraction real, MixedFraction imaginary)
- Creates a complex number from MixedFraction objects as parameter for the real and imaginary part.
- Complex.fromPolar(double r, double theta, {bool angleInRadians = true})
-
Creates a complex number from the given polar coordinates where
r
is the radius andtheta
is the angle. - Complex.fromReal(double real)
-
Creates a complex number having only the real part, meaning that the
imaginary part is set to 0.
const
- Complex.fromRealFraction(Fraction real)
- Creates a complex number having only the real part, which is expressed as a Fraction. The imaginary part is set to 0.
- Complex.fromRealMixedFraction(MixedFraction real)
- Creates a complex number having only the real part, which is expressed as a MixedFraction. The imaginary part is set to 0.
- Complex.i()
-
This is the same as calling
Complex(0, 1)
.const - Complex.zero()
-
This is the same as calling
Complex(0, 0)
.const
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- imaginary → double
-
The imaginary part of the complex number.
final
- isZero → bool
-
Checks whether the complex number is zero.
no setter
- negate → Complex
-
The sign of the current object is changed and the result is returned in a
new Complex instance.
no setter
- real → double
-
The real part of the complex number.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
abs(
) → double -
Computes the square root of (a2 + b2) where
a
is the real part andb
is the imaginary part. -
compareTo(
Complex other) → int -
Compares this object to another object.
override
-
conjugate(
) → Complex - The sign of the imaginary part of current object is changed and the result is returned in a new Complex instance.
-
copyWith(
{double? real, double? imaginary}) → Complex - Creates a deep copy of this object with the given fields replaced with the new values.
-
cos(
) → Complex - Calculates the cosine of this complex number.
-
cot(
) → Complex - Calculates the cotangent of this complex number.
-
exp(
) → Complex - Calculates the base-e exponential of a complex number z where e is the famous Euler constant.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
nthRoot(
int nth) → Complex - Computes the complex n-th root of the complex number. The returned root is the one with the smallest positive argument.
-
phase(
) → double - Converts rectangular coordinates to polar coordinates by computing an arc tangent of y/x in the range from -pi to pi.
-
pow(
num x) → Complex - Calculates the power having a complex number as base and a real value as exponent. The expression is in the form (a + bi)x.
-
reciprocal(
) → Complex - Finds the multiplicative inverse (reciprocal) of the current instance and returns the result in a new Complex object.
-
sin(
) → Complex - Calculates the sine of this complex number.
-
sqrt(
) → Complex - Calculates the square root of a complex number.
-
tan(
) → Complex - Calculates the tangent of this complex number.
-
toPolarCoordinates(
) → PolarComplex -
Returns an instance of PolarComplex which contains the radius
r
and the anglephi
of the complex number. -
toString(
) → String -
A string representation of this object.
override
-
toStringAsFixed(
int fractionDigits) → String -
Prints the real and the imaginary parts of this Complex instance with
fractionDigits
decimal digits. The output produced by this method is the same that would result in callingtoStringAsFixed
on a double: -
toStringAsFraction(
) → String - Prints the real and the imaginary parts or the complex number as fractions with the best possible approximation.
-
toStringWithParenthesis(
) → String - Prints the complex number with opening and closing parenthesis in case the complex number had both real and imaginary part.
Operators
-
operator *(
Complex other) → Complex - Calculates the product of two complex numbers.
-
operator +(
Complex other) → Complex - Calculates the sum between two complex numbers.
-
operator -(
Complex other) → Complex - Calculates the difference between two complex numbers.
-
operator /(
Complex other) → Complex - Calculates the division of two complex numbers.
-
operator <(
Complex other) → bool - There is no natural linear ordering for complex numbers. In fact, any square in an ordered field is >= 0 but in the complex field we have that i2 = -1.
-
operator <=(
Complex other) → bool - There is no natural linear ordering for complex numbers. In fact, any square in an ordered field is >= 0 but in the complex field we have that i2 = -1.
-
operator ==(
Object other) → bool -
The equality operator.
override
-
operator >(
Complex other) → bool - There is no natural linear ordering for complex numbers. In fact, any square in an ordered field is >= 0 but in the complex field we have that i2 = -1.
-
operator >=(
Complex other) → bool - There is no natural linear ordering for complex numbers. In fact, any square in an ordered field is >= 0 but in the complex field we have that i2 = -1.
-
operator unary-(
) → Complex - Returns the negation of this complex number.