Why is using the backslash "\" operator with a diagonal numeric matrix and a symbolic matrix slow?
In the following example we want to solve A*x = B. A is a diagonal numeric matrix and B is a symbolic matrix. Note that using inv(A)*B is much faster than A\B even though mathematically these statements are identical:
%Setup. A is type double, B is symbolic
syms x y zI = eye(3);B = [x;y;z];B = B.^2 - 3;%%Test A\B
ticfor i = 1:100 A = I*i; A\B;endtoc%%Test inv(A)*B
ticfor i = 1:100 A = I*i; inv(A)*B;endtoc
Best Answer