Class ComplexNumber

java.lang.Object
com.aidano7.bison.algebra.ComplexNumber

public class ComplexNumber
extends java.lang.Object
Since:
3/28/21
Version:
v0.1

This class is for the implementation of a complex number. A complex number is a number with a real and imaginary part. The unit i is defined as the square root of -1.

Author:
aidano-7
  • Field Summary

    Fields
    Modifier and Type Field Description
    static ComplexNumber i
    The complex number for i
  • Constructor Summary

    Constructors
    Constructor Description
    ComplexNumber​(float realNumber, float imaginaryNumber)
    Creates an instance of a complex number with its real and imaginary parts defined.
  • Method Summary

    Modifier and Type Method Description
    void add​(ComplexNumber complexNumber)
    Adds this and complexNumber using the static method in ComplexNumber.
    static ComplexNumber add​(ComplexNumber complexNumberA, ComplexNumber complexNumberB)
    To add a complex number to another, simply add the real part, then the imaginary part.
    void divide​(ComplexNumber complexNumber)
    Divides this and complexNumber using the static method in ComplexNumber.
    static ComplexNumber divide​(ComplexNumber complexNumberA, ComplexNumber complexNumberB)
    To divide a complex number by another, the real part of the quotient is defined as (ac + bd) / (a ^ 2 + b ^ 2), and the imaginary part is (ad - cb)i / (a ^ 2 + b ^ 2).
    boolean equals​(ComplexNumber complexNumber)
    Checks if complexNumber is equal to this.
    float getImaginaryNumber()
    Returns the the imaginary part of the complex number.
    float getRealNumber()
    Returns the the real part of the complex number.
    void multiply​(ComplexNumber complexNumber)
    Multiplies this and complexNumber using the static method in ComplexNumber.
    static ComplexNumber multiply​(ComplexNumber complexNumberA, ComplexNumber complexNumberB)
    To multiply a complex number by another, the equation ac + adi + bci + bdi ^ 2 is used.
    void setImaginaryNumber​(float imaginaryNumber)
    Sets the the imaginary part of the complex number.
    void setRealNumber​(float realNumber)
    Sets the the real part of the complex number.
    void square()
    Squares this using the static method in ComplexNumber.
    static ComplexNumber square​(ComplexNumber complexNumber)
    Squaring a complex number is the same as multiplying it by itself, so writing another function is not necessary.
    void subtract​(ComplexNumber complexNumber)
    Subtracts this and complexNumber using the static method in ComplexNumber.
    static ComplexNumber subtract​(ComplexNumber complexNumberA, ComplexNumber complexNumberB)
    To subtract a complex number to another, simply subtract the real part, then the imaginary part.
    java.lang.String toString()
    Complex numbers are written as a + bi.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • i

      public static final ComplexNumber i
      The complex number for i
  • Constructor Details

    • ComplexNumber

      public ComplexNumber​(float realNumber, float imaginaryNumber)
      Creates an instance of a complex number with its real and imaginary parts defined.
      Parameters:
      realNumber - the real part of the complex number
      imaginaryNumber - the imaginary part of the complex number
  • Method Details

    • add

      public static ComplexNumber add​(ComplexNumber complexNumberA, ComplexNumber complexNumberB)
      To add a complex number to another, simply add the real part, then the imaginary part.
      Parameters:
      complexNumberA - the first number to add
      complexNumberB - the second number to add
      Returns:
      c the sum of a and b
    • subtract

      public static ComplexNumber subtract​(ComplexNumber complexNumberA, ComplexNumber complexNumberB)
      To subtract a complex number to another, simply subtract the real part, then the imaginary part.
      Parameters:
      complexNumberA - the first number to subtract
      complexNumberB - the second number to subtract
      Returns:
      c the difference of a and b
    • multiply

      public static ComplexNumber multiply​(ComplexNumber complexNumberA, ComplexNumber complexNumberB)
      To multiply a complex number by another, the equation ac + adi + bci + bdi ^ 2 is used. In this syntax, a is the first number's real part, b is the first number's complex part, c is the second number's real part, and b is the second number's complex part.
      Parameters:
      complexNumberA - the first number to multiply
      complexNumberB - the second number to multiply
      Returns:
      c the product of a and b
    • divide

      public static ComplexNumber divide​(ComplexNumber complexNumberA, ComplexNumber complexNumberB)
      To divide a complex number by another, the real part of the quotient is defined as (ac + bd) / (a ^ 2 + b ^ 2), and the imaginary part is (ad - cb)i / (a ^ 2 + b ^ 2). In this syntax, a is the first number's real part, b is the first number's complex part, c is the second number's real part, and b is the second number's complex part.
      Parameters:
      complexNumberA - the first number to divide
      complexNumberB - the second number to divide
      Returns:
      c the quotient of a and b
    • square

      public static ComplexNumber square​(ComplexNumber complexNumber)
      Squaring a complex number is the same as multiplying it by itself, so writing another function is not necessary.
      Parameters:
      complexNumber - the number to get squared
      Returns:
      c the complexNumber squared
    • getRealNumber

      public float getRealNumber()
      Returns the the real part of the complex number.
      Returns:
      realNumber the real part of the complex number
    • setRealNumber

      public void setRealNumber​(float realNumber)
      Sets the the real part of the complex number.
      Parameters:
      realNumber - the real part of the complex number
    • getImaginaryNumber

      public float getImaginaryNumber()
      Returns the the imaginary part of the complex number.
      Returns:
      imaginaryNumber the imaginary part of the complex number
    • setImaginaryNumber

      public void setImaginaryNumber​(float imaginaryNumber)
      Sets the the imaginary part of the complex number.
      Parameters:
      imaginaryNumber - the imaginary part of the complex number
    • toString

      public java.lang.String toString()
      Complex numbers are written as a + bi.
      Overrides:
      toString in class java.lang.Object
      Returns:
      string the standard form of the complex number
    • add

      public void add​(ComplexNumber complexNumber)
      Adds this and complexNumber using the static method in ComplexNumber.
      Parameters:
      complexNumber - the number to add
    • subtract

      public void subtract​(ComplexNumber complexNumber)
      Subtracts this and complexNumber using the static method in ComplexNumber.
      Parameters:
      complexNumber - the number to subtract
    • multiply

      public void multiply​(ComplexNumber complexNumber)
      Multiplies this and complexNumber using the static method in ComplexNumber.
      Parameters:
      complexNumber - the number to multiply
    • divide

      public void divide​(ComplexNumber complexNumber)
      Divides this and complexNumber using the static method in ComplexNumber.
      Parameters:
      complexNumber - the number to divide
    • square

      public void square()
      Squares this using the static method in ComplexNumber.
    • equals

      public boolean equals​(ComplexNumber complexNumber)
      Checks if complexNumber is equal to this.
      Parameters:
      complexNumber - the number to check equality against this
      Returns:
      boolean true if complexNumber === this