# Can we make such matlab code so that every time we run the program it will return the same randomly generated matrices?

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

-

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.

-
Dear i want to generate 100*100 random matrices. I want the same matrix to come every time i run the program. How to do? Thanks – srijan Sep 22 '12 at 5:00
@srijan: Same matrix, or same matrices? – Rod Carvalho Sep 22 '12 at 5:02
@srijan See my edit for specific code to generate the same matrix multiple times. – Daryl Sep 22 '12 at 5:06
@RodCarvalho I want same matrix to come every time I run the program.... – srijan Sep 22 '12 at 5:06
You can save it to a .mat file with the commane save [filename] [variables] where I have used square brackets to indicate where you should type your respective parameters. To load them again, use the load command. See save and load. – Daryl Sep 22 '12 at 5:17