0

I was comparing the time that the computer takes to perform Partial Pivoting, Total Pivoting and multiplying by the inverse. The code (that makes the comparison chart) is as follows:

ListPlot[{Table[
   AbsoluteTiming[
     SolGaussPivote[RandomReal[100, {10, 10}], 
      RandomReal[100, {10, 1}]]][[1]], 300], 
  Table[AbsoluteTiming[
     SolGauss3[RandomReal[100, {10, 10}], RandomReal[100, {10, 1}]]][[
    1]], 300], 
  Table[AbsoluteTiming[
     Inverse[RandomReal[100, {10, 10}]] . 
      RandomReal[100, {10, 1}]][[1]], 300]}]

The chart shows that partial pivoting takes way less than time than total pivoting but it shows Inverse as it took 0 time. Where is the problem?

  • I do not know why you say it takes $0$ time. Using A=RandomReal[1,{10,10}]; First[RepeatedTiming[Inverse[A]]] I find (on my machine) that this takes about $10^{-5}$ seconds. That is not $0$. For a larger matrix, it will be more. So, what is your question? – user293787 Nov 25 '22 at 15:55
  • Why does the inverse take so much less than Gauss? Isnt Inverse supposed to take a lot? – Pedro García Nov 25 '22 at 15:56
  • Where are SolGaussPivote and SolGauss3 defined? – Chris K Nov 25 '22 at 16:41

1 Answers1

5

You seem to assume that you are comparing algorithms, but in fact you are comparing specific implementations of algorithms. Inverse and matrix multiplication are built-in operations that have highly optimized implementations.

To compare algorithms, look at how their timing scales with the matrix size, don't just test them on matrices of one specific size. Timings on inputs of one specific size will not tell us anything about how efficient an algorithm is.

Just think about how the same for loop (i.e. the same algorithm) will run much faster if written in the C language (one implementation) than if it's written in a high-level language like Mathematica or Python (a different implementation).

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263