Vector.equals()

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, 6 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1813
    avatar
    kevinsun
    Participant

    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:
            assertTrue(A.toString().equals(B.toString()));
            assertTrue(A.equals(B));
    I got True for the first line but False for the second.

    Any thought? Thx

    #1953
    avatar
    Haksun Li
    Moderator

    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:

    #1954
    avatar
    Haksun Li
    Moderator

    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
    Parameters:
    A1 – a matrix
    A2 – a matrix
    epsilon – a precision parameter: when a number |x| ≤ ε, it is considered 0
    Returns:
    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.