I have made following matlab code for computing cpu time of matlab inbuilt function pinv(A) to compute the Pseudo inverse of a given matrix. I had runed the matlab code 1000 times & calculated the mean of the results.
Matlab code
A = rand(10) % given randomly generated matrix of order 10
REPS = 1000; % taking thousand times repetitions
minTime = Inf;
tic
for i=1:REPS
tstart = tic;
x1=pinv(A)
telapsed = toc(tstart);
minTime = min(telapsed,minTime);
end
execTime = toc; % total execution time
averageTime = execTime/REPS
I am not sure whether my program is correct or not? I have to use these results for my project work. Could anybody help me with this. I would be very much thankful to you.
execTimeis the total execution time.averageTimeis the average time to calculate the pseudoinverse.minTimeis the minimum time for one iteration.You are also likely to get more accurate results if each iteration takes longer (See here for issues when the execution time is too short). The easiest way to do this is to increase the size of
– Daryl Sep 18 '12 at 07:33A, such asA=rand(100). Depending on your machine, this still may not be large enough.Aso small in size. As I suggested above, make the coefficient matrixAlarger, so that the total execution time is longer for each iteration. (I will post these comments as an answer.) – Daryl Sep 18 '12 at 08:55A = rand(10)to be inside the loop? This way you'll just get the average time it takes to invert one particular random matrix; if you want to average over different random matrices, you need to put the line that generates the random matrices inside the loop. – joriki Sep 19 '12 at 11:41