Borrar filtros
Borrar filtros

checking if a value is equal to zero

22 visualizaciones (últimos 30 días)
Oskar
Oskar el 19 de Dic. de 2017
Comentada: the cyclist el 19 de Dic. de 2017
I need a script to find whether the value of a determinant of a matrix is equal to zero, and to end the program if it is and carry on if it isn't.

Respuestas (2)

Steven Lord
Steven Lord el 19 de Dic. de 2017
Don't use det to try to determine if a matrix is singular.
A = 0.1*eye(400);
det(A)
B = 1e10*[1 1; 1 1+eps];
det(B)
A is a non-zero scalar multiple of the identity matrix and so is not singular, but the determinant underflows to 0.
B is extremely close to singular, but its determinant is close to 20000 because its elements are so large.
Instead of using det to determine if a matrix is singular, use cond to compute the condition number. The closer to 1 the condition number is, the better conditioned the problem is.
cond(A) % 1
cond(B) % around 2e16

the cyclist
the cyclist el 19 de Dic. de 2017
You could put code like this in your function.
% Make up a matrix. Use your matrix here.
M = rand(7);
% Calculate determinant
detM = det(M);
tol = 1.e-6; % Should not check floating point numbers for exact equality, so define a tolerance
if abs(detM) < tol
return
end
  1 comentario
the cyclist
the cyclist el 19 de Dic. de 2017
If you use this answer, be sure to consider Steven Lord's advice, too, about using determinant.

Iniciar sesión para comentar.

Categorías

Más información sobre Linear Algebra en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by