Accuracy of results in symbolic variable and double

6 views (last 30 days)
Hello there, I have wriiten a code to genrate some generalized matrix and now I am performing some matrix operations like inversion, addition over that matrix. So i observed two things:
  1. If I use symbolic variable to create that particular matrix, say A, then the programm is taking too much time (as the order of matrix around 1000) to do the computaion and
  2. If I don't use symbolic variables to create that matrix then I get all the results in double (which is obvious and the time taken by the code is also very less) but the results are different than the one I got from symbolic method. For example the inverse is not coming out as exact.
I understand the problem of double values but is there any way that I can avoid this problem. Is there any solution that without using the symbolic I can get the exact result?
Any help is appreciated. Thanks in the advance.
  5 Comments
Walter Roberson
Walter Roberson on 16 Jul 2020
I have encountered matrices that were non-singular in theory, but singular in practice. In some of the cases, adding more digits by using software floating point (vpa() and symbolic toolbox) was enough. A couple of times any finite precision would not have been enough (though it can then be difficult to prove that theoretically infinite precision would be enough in those cases.)
If you do use the symbolic toolbox, watch out for the fact that by default the symbolic toolbox approximates floating point numbers. For example
>> sym(pi-313*eps)
ans =
pi
>> sym(pi-314*eps)
ans =
7074237752028283/2251799813685248
It is quite common to find that the approximation done is what you would like to be done, that it ends up restoring the theoretical values that got approximated numerically to form the number in your array... but because it is an approximation, it can get it wrong. So sometimes you should sym(pi-313*eps,'f') or sym(pi-313*eps, 'd')... but if you are going to do the later, you should probably be using something like sym('3.14159265358972383808122685877606') because sym() does not get handed the number until it has already been approximated as floating point.
John D'Errico
John D'Errico on 16 Jul 2020
No. I never wrote a matrix inverse for HPF. It would not be difficult.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 16 Jul 2020
No, there is no way around that problem.
The numeric approximation of your coefficients into floating-point can destroy your theoretical accuracy. https://blogs.mathworks.com/cleve/2013/02/02/hilbert-matrices/
You can reduce the numeric problems by never using inv(). Use the / or \ operators instead.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!