MATLAB: Rank of Symbolic Matrix returns incorrectly

invmatrixranksymbolic

Hello all,
I am trying to invert a 5×5 matrix of mixed symbolics and numbers. All columns are linearly independent, concluded by inspection. However rank() returns 4 and the inverse of the matrix returns a 5×5 matrix where all elements are Inf.
Is there a better way to invert this matrix? It is not singular, as an inverse is returned, but it seems to be of indeterminate form.
Code:
% define coefficients
mu1 = sym('mu1');
mu2 = sym('mu2');
mu3 = sym('mu3');
gam1 = sym('gam1');
gam2 = sym('gam2');
gam3 = sym('gam3');
L = sym('L');
% define matrices
B = [1 -1 -1 0 0
gam1/mu1 gam2/mu2 -gam2/mu2 0 0
0 exp(-gam2*L) exp(gam2*L) -exp(-gam3*L) -exp(gam3*L)
0 (-gam2/mu2)*exp(-gam2*L) (gam2/mu2)*exp(gam2*L) (gam3/mu3)*exp(-gam3*L) (-gam3/mu3)*exp(gam3*L)
0 0 0 0 0]
rank(B)
inv(B)

Best Answer

An array with a row or column that is all zero cannot be full rank. It is not enough for columns to be linearly independent: rows must be as well.