# Approximate results

I am trying to show that two matrices are the same.

One matrix has random elements drawn from a distribution of $${(-0.75,-0.25,0,0.25,0.75,0.95)}$$, while the other has values with imaginary parts too (but they are close to the entries $${(-0.75,-0.25,0,0.25,0.75,0.95)}$$). In fact, they need to be the same when I approximate the matrix with imaginary elements.

I have tried both N and Round but, when using Round, the elements of the matrix with complex entries approximate to 1, -1.

Hence, what command shall I use so that the two matrices are the same?

• You may want to use Re to only get the real parts of the second matrix? Feb 19, 2019 at 22:37
• Yes. That works. I used Chop as well to approximate the very small values to 0. However, when I try to test it, it does not give me the answer "True" or "False". I am using MatrixForm[A]==MatrixForm[B]. Does the command not work for matrices?
– user62722
Feb 19, 2019 at 22:54
• MatrixForm should be used only for display: mathematica.stackexchange.com/questions/3098/… and mathematica.stackexchange.com/questions/18393/… detail that. A == B is what you're looking for. Feb 19, 2019 at 22:56
• What I did precisely is: $"Re[B]==A"$. When not using MatrixForm, it says it is false. I double-checked and both A and B are defined as a list. I checked it visually and the two are the same.
– user62722
Feb 19, 2019 at 23:02
• Please update your question with copy-pasteable code so that we can see exactly what we're working with :) Feb 19, 2019 at 23:09

Make a matrix:

m = {{0., -1.}, {1., 0.}}


Put in some small imaginary parts:

mapp = m + I 10^-10


Check for equality:

m == mapp
(* False *)


Mathematica has heuristics for approximate equality. If they aren't working for your specific problem, you may have to come up with a better measure, for example:

Norm[m - mapp] < 10^-9
(* True *)
{"ft_lang_label":"__label__en","ft_lang_prob":0.91378725,"math_prob":0.92152905,"size":818,"snap":"2023-14-2023-23","text_gpt3_token_len":218,"char_repetition_ratio":0.11547912,"word_repetition_ratio":0.0,"special_character_ratio":0.29217604,"punctuation_ratio":0.20744681,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9914026,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-03-26T02:01:51Z\",\"WARC-Record-ID\":\"<urn:uuid:05dff488-8cff-4721-a443-d408e11d9045>\",\"Content-Length\":\"148583\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:d3548564-539a-43ad-a97b-db8deaa1b2be>\",\"WARC-Concurrent-To\":\"<urn:uuid:e156fe53-5136-4f0e-b709-0385f19a89b0>\",\"WARC-IP-Address\":\"151.101.193.69\",\"WARC-Target-URI\":\"https://mathematica.stackexchange.com/questions/191856/approximate-results\",\"WARC-Payload-Digest\":\"sha1:DLIXCVD236AIF53H2CDEFYIVKHW5KXH5\",\"WARC-Block-Digest\":\"sha1:OSVHYXHXGUUH6GW2WH2NSBOHYPFX5NRR\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-14/CC-MAIN-2023-14_segments_1679296945381.91_warc_CC-MAIN-20230326013652-20230326043652-00395.warc.gz\"}"}