1
$\begingroup$

I am running a gamblers problem solution where I am testing the timing involved in solving the Ax = b equation for matrices of n=100, 1000, 10000, and 100000. For some reason I keep getting the same time (0.015625 seconds) for the time, but I know it takes many more seconds than this. The matrix for n=100000 ran for probably 20 mins and still returned 0.015625.

My process to create the matrix is basically:

 A = IdentityMatrix[100000, SparseArray];
 For[i = 2, i < 100000, i++,
 A[[i, i]] = -1;
 A[[i, i - 1]] = .5;
 A[[i, i + 1]] = .5
 ];

The vector is created by:

b = {1};
For[i = 2, i <= 100000, i++, b = Insert[b, 0, -1] ];

Then I run:

Timing[LinearSolve[A, b]]
$\endgroup$
  • $\begingroup$ What are matrixSize, vectorSize and coefficientMatrix? $\endgroup$ – Henrik Schumacher Mar 14 '19 at 22:34
  • $\begingroup$ Sorry, I removed those variables. $\endgroup$ – Jaigus Mar 14 '19 at 22:42
  • $\begingroup$ What happens if you use AbsoluteTiming instead of Timing? $\endgroup$ – Michael E2 Mar 14 '19 at 22:42
  • 1
    $\begingroup$ Related: mathematica.stackexchange.com/questions/14152/… $\endgroup$ – Michael E2 Mar 14 '19 at 22:44
  • $\begingroup$ AbsoluteTiming doesn't give me the same number anymore, yet it still gives a very small number. $\endgroup$ – Jaigus Mar 14 '19 at 22:59
1
$\begingroup$

I cannot tell what the problem with the timing is but I can show you how to set up and solve the system quicker:

First@AbsoluteTiming[
 n = 100000;
 A = SparseArray[{
  Band[{1, 1}] -> -1., 
  Band[{2, 1}] -> 0.5, 
  Band[{1, 2}] -> 0.5
  }, 
  {n, n}];
 b = Normal[SparseArray[{1} -> 1., {n}]];
 x = LinearSolve[A, b];
 ]

0.665885

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.