Home 2015 Forums Numerical Method Linear Algebra Vector.equals()

This topic contains 2 replies, has 2 voices, and was last updated by avatar Haksun Li 8 years, 2 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #1813

    Could anyone tell me how Vector.equals() checks the entries? Is there any precision tolerance for doubles?

    I have a problem here:
    A, B are Vector of doubles, for the code:
    I got True for the first line but False for the second.

    Any thought? Thx

    Haksun Li

    The way you do eqality checking for Vector is wrong.

    To check to see if two vectors are absolutely equal, you may do as follows.

    Note that the numerical values must have exactly the same binary representations in memory for this to work. The equality check method is essentially an override of

    To allow a precision parameter in the “equality” checking, which is most often the case in numerical computing, you may do:

    Haksun Li

    The method to check [tt:1n1cmq34]Matrix[/tt:1n1cmq34] equality with a precision is:

    public static boolean equal(DoubleMatrix< ?> A1,
                                DoubleMatrix< ?> A2,
                                double epsilon)

    Check the equality of two matrices. Two matrices are equal iff
    1.the dimensions are the same;
    2.all entries are equal
    A1 – a matrix
    A2 – a matrix
    epsilon – a precision parameter: when a number |x| ≤ ε, it is considered 0
    true iff all entries are equal, entry by entry

    For example, in JUnit test cases, we write:

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.