Matlab Matrix Multiplication Calculate significant digits

I have two matrices in the form of variables A and b , which are inputs to my matlab function (published below). I would like to calculate the Significant numbers used for the inverse matrix operation (division of the matrix) from the results of A , b . However, I do not know where to start (Matlab or mathematically) to discuss this approach. Help?

More context using a square linear system (Ax=b) , and I see singular or nonsingular and trying to find the solution (s).

 % x = answer % y = 0 if no solution, 1 if nonsingular, 2 if many solutions % z = p is number of sig figs % function [ x, y, z ] = squareLinSysSolv(A, b) if det(A) == 0 % Matrix is singular and therefor many solutions x = A\b; y = 0; % Used as place holder to compile z = 5; % Used as place holder to compile elseif det(A) ~= 0 % Matrix does not equal to zero (perhaps a number very close to it or % far from it) and therefor has a unique solution. x = A\b; y = 1; % Used as place holder to compile z = 5; % Used as place holder to compile end end 

Edit: To make this a bit clear, z must be some integer that approximates (ceiling or floor value) the decimal number of significant digits that A\b were calculated on.

Test cases: Test / specification of what is expected. Both A and b are matrices, and the result should be something like this.

 A = 1.5000 2.3000 7.9000 6.1000 3.2000 13.0000 13.0000 21.0000 76.0000 b = 1 3 5 >> [x,y,z] = squareLinSysSolv(A,b) % the result of x = A\b x = 0.8580 3.0118 -0.9132 % determinant is not equal to zero y = 1 % Amount of sig figs/precision in calculation z = 15 
+6
source share
3 answers

I'm with Dan here. I do not understand the question, and do not see how / where you calculate z. First of all, the digits in the display of your answer do not depend on the number of significant digits when calculating the answer. Secondly, you have two cases: det (A) == 0 and det (A) ~ = 0. In both cases, it seems that you set z = 5. (You should do something in a different place, which you do not show for calculation z = 15? How did you calculate your z?)

Also, find out that the number of significant digits will be a function of the class of your data. Double> single> integer ...

And ... just for efficiency, I don’t know the size of A (and how much overhead is involved in calculating its determinant), but there is no reason to calculate it twice:

 if det(A)==0 % case 1 else % NOT: elseif det(A)~=0 % case 2 end 

I think I'm tight too. :)

Brett

+1
source

How close the matrix is ​​to unity, as a rule, the condition number is quantified. There are several ways to evaluate the condition number of a matrix. One common method is to calculate the ratio of the largest and smallest eigenvalues ​​of a quantity.

Matlab has a built-in cond function that gives the condition number for the matrix (relative to the inverse). Values ​​around 1 are "good" - I'm not sure how to relate to anything specific, like "significant numbers."

+1
source

If the question you ask is "Given the decimal representation of matlab floating point numbers, then what is the smallest number z such that after the first digits z are zero", then I think the next function will be more - or less .

I will add a disclaimer that, although I tested this on a bunch of numbers, it is possible that I missed the case, so you'll want to test it thoroughly. This can be done more efficiently in a single pass through the string.

 function n = sig_decimal_digits(f) % get string representation, any decimal point, and any leading zeros str = num2str(f,20); % strip any exponent part loc = regexp(str, 'e'); if ~isempty(loc) str = str(1:(loc-1)); end % strip any decimal point str = strrep(str, '.', ''); % strip any leading zeros (and minus sign!) loc = regexp(str, '[1-9]'); if isempty(loc) %if *only* leading zeros, f is 0, so n = 1 n = 1; return; else str = str(loc:end); end % count length of string, excluding trailing zeros loc = regexp(str, '0+$'); if isempty(loc) n = length(str); else n = loc-1; end end 

However, I will add two comments:

  • This obviously has nothing to do with matrix multiplication, so I'm not sure why you introduced this into it.
  • This is a strange quantity that needs to be calculated. If your matrices do not have any special numbers, the answer will almost always be 17, since most floating point numbers do not have short decimal expansions. For example, for A and b that you ask in your question, all three numbers in x have 17 significant digits according to my function.
0
source

All Articles