资源简介
线性同余法求一个随机矩阵,实现矩阵的随机产生。
代码片段和文件信息
function random20
%RNDGEN Uniformly distributed random numbers generator.
% Linear congruential random number generators
% X is a random number vector get from
% X = (a*X+c) mod m
% X0 is the inital value of X which is also called SEED.
% m=16 a=5 and c=1 will give a random seriers
% See also RAND RNDGENM
n=20 ;
a = 5;
c = 1;
m = 16;
x0= 1;
xt(1)= mod(a*x0+cm);
for i = 1:n
xt(i+1)= mod(a*xt(i)+cm);
kesai(i)= xt(i)/m;
end
%xt=xt(end-n+1:end);
xt
disp(‘伪随机数列kesai:‘)
kesai
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 562 2010-04-13 21:48 线性同余法matlab程序\random.m
目录 0 2010-04-13 22:12 线性同余法matlab程序
----------- --------- ---------- ----- ----
562 2
评论
共有 条评论