Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab Matrix Multiplication Calculate Significant Figures

I have two matrices in the form of the variables A and b that are inputs to my matlab function (posted below). I would like to calculate the significant figures used for the matrix inverse operation (matrix division) from the result A, b matrices. However, I have no idea where to start (matlab or mathematically) to go about this approach. Help?

More context, using a square linear system (Ax=b) and I am seeing if its singular or nonsingular and trying to find a 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 it a bit clear, z should be some integer which approximates (ceiling or floor value) a decimal number of significant figures at which A\b were calculated at.

Test Cases: Test/Spec sheet of what is expected. Both A and b are matrices and the result should be something like so.

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
like image 235
Adam Avatar asked Oct 25 '12 17:10

Adam


People also ask

How do I get more significant figures in MATLAB?

By default, MATLAB® uses 16 digits of precision. For higher precision, use the vpa function in Symbolic Math Toolbox™. vpa provides variable precision which can be increased without limit. When you choose variable-precision arithmetic, by default, vpa uses 32 significant decimal digits of precision.

How do you round to 3 significant figures in MATLAB?

Y = round( X , N ) rounds to N digits: N > 0 : round to N digits to the right of the decimal point.

What is the difference between array multiplication and matrix multiplication in MATLAB?

Matrix operations follow the rules of linear algebra. By contrast, array operations execute element by element operations and support multidimensional arrays. The period character ( . ) distinguishes the array operations from the matrix operations.


2 Answers

I'm with Dan here. I don't understand the question, nor do I see how/where you're calculating z. First of all, the number digits in the display of your answer is independent of the number of significant digits in the calculation of the answer. Second, you have two cases: det(A)==0, and det(A)~=0. In both cases, it appears that you are setting z = 5. (You must be doing something elsewhere that you're not showing to calculate z = 15? How did you calculate your z?)

Also, recognize 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 (nor how much overhead is entailed in computing its determinant), but there's no reason to compute it twice:

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

I guess I'm being dense, too. :)

Brett

like image 91
Brett Shoelson Avatar answered Oct 08 '22 09:10

Brett Shoelson


How close a matrix is to being singular is typically quantified by a "condition number". There are several ways to estimate the condition number of a matrix. One common technique is to calculate the ratio of the largest and smallest magnitude eigenvalues.

Matlab has a built-in function called cond that gives the condition number for a matrix (with respect to inversion). Values near 1 are "good"--I'm not sure how to relate it to anything concrete like "significant figures".

like image 25
nibot Avatar answered Oct 08 '22 08:10

nibot