3
$\begingroup$

I have two matrices mat1 and mat2, both are results from different algorithms that are supposed to calculate the same result. The nmax is around 300, the q varies from 0.001 to 1.

expr1 = Exp[-q^2/2] Sum[q^(i + j - 2 k) (-1)^(-k + j) (Sqrt[i!] Sqrt[j!])/((i - k)! (j - k)! k!), 
                        {k, 0, Min[i, j]}];

expr2 = Exp[-q^2/2] Sqrt[j!/i!] q^(i - j) LaguerreL[j, i - j, Abs[q]^2];

mat1 = Table[expr1, {i, 0, nmax}, {j, 0, nmax}];

mat2 = Table[expr2, {i, 0, nmax}, {j, 0, nmax}];

What would be the best method of comparing them depending on q to see if they are close enough to be considered the same result? Thanks in advance for the advices.

$\endgroup$
  • 3
    $\begingroup$ can't you take just the norm of the difference of the 2 matrices? There are number of norms defined for matrices. reference.wolfram.com/language/ref/Norm.html may be pick the appropriate norm for your needs, as in Norm[mat1-mat2, "Frobenius"] ? This will work for sparse matrices as well. $\endgroup$ – Nasser Oct 26 '14 at 20:46
0
$\begingroup$
expr1 = Exp[-q^2/2] Sum[
    q^(i + j - 2 k) (-1)^(-k + j) (Sqrt[i!] Sqrt[j!])/((i - k)! (j - k)! k!), {k, 0,Min[i, j]}];
expr2 = Exp[-q^2/2] Sqrt[j!/i!] q^(i - j) LaguerreL[j, i - j, Abs[q]^2];
mat1 := Table[expr1, {i, 0, nmax}, {j, 0, nmax}];
mat2 := Table[expr2, {i, 0, nmax}, {j, 0, nmax}];

nmax = 30; mat1 // Dimensions

{31, 31}

matb1 = mat1 /. Abs[a_]^b_?EvenQ -> a^b // Simplify;
matb2 = mat2 /. Abs[a_]^b_?EvenQ -> a^b // Simplify;

stlist = Select[matb1 - matb2 // Flatten // Union, (# =!= 0 &)];
stlist // FullSimplify

{0, 0, 0, 0, 0}

$\endgroup$
  • $\begingroup$ Does this true for any q > 0? $\endgroup$ – Suro Oct 26 '14 at 22:18
  • $\begingroup$ @Suren Sure, that is symbolically same. $\endgroup$ – Junho Lee Oct 26 '14 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.