![]() Remaining singular values of R1, per MATLAB double precision, range from 1.48e-8 down to 1.57e-37. Norm(R1) = 1.76e8 (largest singular value) Here is R1, as computed in MATLAB: 1.0e+07 * Again, this might be implemented in slightly different ways in the two languages, and possibly also depend on the result of previous computations. Both languages may include optimizations to map A*B where A and/or B are symmetric to a specialized BLAS call ( DSYMM).I'm not sure Python does that, too, and if it does it might map them to a slightly different call when something like (A*B.').' is used. Matlab includes special tricks to detect multiplications of the form A*B', A*B.', A*A' and map them to a single BLAS call.Different optimization could rearrange sums in different ways (using associativity), and give slightly different results. They are not guaranteed to yield the exact same result up to the last bit. Matlab and Python are probably linked to different versions of the BLAS libraries.There are several very BLAS-specific reasons why this could happen: Third, the real question here is why the results do not coincide exactly, since both languages call some BLAS library functions for their computations. Second, realize that this is the reason why people told you to use relative errors in your numerical analysis class. Stone's answers, which is completely correct. This will perform the operations and will compare both results in terms of its norm-2.įinally, my Python version is 3.6.3, with numpy (1.14.3) and scipy (1.1.0).įirst, see Mark L. This will perform the operations and will generate a python_results.mat file. Does anyone know what the reason could be?įor the sake of clarity, I attach the data and the scripts here. I am not able to understand why the results are different. ![]() However, the same operation on same data produces different results in terms of norm-2, namely: norm-2(R1-R2) = 7.4506e-09 In my Python code I have the same matrices and the operation looks as follows: R2 = np.matmul(A, np.matmul(-(np.multiply(B, C) + np.multiply(D, C)), E.transpose()).transpose()) Previous set of operations produces a 6x5 matrix (R1 matrix). ![]() Assuming we have following data: A: 6圆 matrix ![]() I am translating some Matlab code into Python and I having some problems regarding matrix multiplication accuracy. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |