MATLAB: 1/X & X^-1 are they the same

reciprocals matlab

i'm about to write something that involves alot of reciprocals.
i want to know is 1/X the same as X^-1?
mathematically its the same, but which does matlab prefers? (that can make it simulate faster)
or are they really the same?

Best Answer

clear all, clc
ver
% ---------------------------------------------------------------------------

% MATLAB Version 7.13.0.564 (R2011b)
% OperatingSystem: MicrosoftWindows7 Version6.1 (Build7601: ServicePack1)
% Java VM Version: Java 1.6.0_17-b04 with Sun Microsystems Inc.
% Java HotSpot(TM) Client VM mixed mode
% ---------------------------------------------------------------------------
X = randn(100);
for j = 1:5
tic
for i = 1:1e5
invX1 = eye(100)/X;
end
time1(j) = toc % 47.9 46.8 47.3 46.5 46.9
tic
for i = 1:1e5
invX2 = X^(-1);
end
time2(j) = toc % 62.6 62.8 62.6 61.9 62.3
for i = 1:1e5
invX3 = inv(X);
end
time3(j) = toc % 98.7 96.3 96.5 97.8 97.2
end
Hope this helps.
Greg