4
$\begingroup$

I want to compare efficiency of two iteration methods for computing inverse of a matrices. I want to test performance of these methods on some randomly generated matrices. I want to know can we make such matlab code so that every time we run the program it will return the same randomly generated matrices. Could anybody answer me? I would be very much greatfull to you.

Thanks

1 Answers 1

4

In the new versions, use rng('default') to set the seed for the random number generator.

In older versions, it is something like rand('seed','twister'); but I don't remember exactly.

Either way, the first method is recommended by MATLAB.

Edit: here is code to generate random matrix of size $100$

n=100; %size of matrix rng('default'); % set random seed to matlab default A = rand(n,n); % generate random matrix 

If you run this same code multiple times, you will get the same A each time.

  • 0
    @Daryl thank you very much dear.2012-09-25