标签:amd 随机过程 空间 参考资料 elseif val clear label legend
P = [0.2, 0.3, 0.5; 0.5, 0.1, 0.4; 0.6, 0.2, 0.2];
% 给出一步转移矩阵
S = [1, 2, 3];
n = 1;
% 给出状态空间 X
%初始时刻
N = 100; %迭代步数
i = 1;
U = rand;
Compare2 = sum(P(i,1:2));% 累加获得概率
Compare3 = sum(P(i,:));
if (U < P(i,1))
Y(i) = 1;
elseif ((U > P(i,1))&(U < Compare2))
Y(i) = 2;
elseif ((U > Compare2)&(U < Compare3))
Y(i) = 3;
end
X(1) = Y(i);
while (n < N)
i = X(n);
U = rand;
if (U < P(i,1))
Y(i) = 1;
elseif ((U > P(i,1))&(U < Compare2))
Y(i) = 2;
elseif ((U > Compare2)&(U < Compare3))
Y(i) = 3;
end
n = n+1;
X(n) = Y(i);
endxlab = 1:1:100;
stairs(xlab,X)
axis([0 100 0 10])
title('离散时间马尔可夫链仿真')
xlabel('步长 n')
ylabel('状态 x(n)')
legend('样本函数 1')
clear
clc
U = rand;
lamda = 2;
% 这里给定值
T = 10; % 这里给定值
t = 0;
N1 = 0;
E = -log(U)/lamda;
t = t + E;
while (t <= T)
N1 = N1 + 1;
t1Value(N1) = t;
U = rand;
E = -log(U)/lamda
t = t + E;
end
irt1 = 1:1:N1;
stairs(t1Value,irt1,'r')
hold on;
U = rand;
lamda = 2;
% 这里给定值
T = 10; % 这里给定值
t = 0;
N2 = 0;
E = -log(U)/lamda;
t = t + E;
while (t <= T)
N2 = N2 + 1;
t2Value(N2) = t;
U = rand;
E = -log(U)/lamda;
t = t + E;
end
irt2 = 1:1:N2;
stairs(t2Value,irt2,'b')
hold on;
U = rand;
lamda = 2;
% 这里给定值
T = 10; % 这里给定值
t = 0;
N3 = 0;E = -log(U)/lamda;
t = t + E;
while (t <= T)
N3 = N3 + 1;
t3Value(N3) = t;
U = rand;
E = -log(U)/lamda;
t = t + E;
end
irt3 = 1:1:N3;
stairs(t3Value,irt3,'g')
axis([1 15 0 32])
title('泊松过程模拟结果')
xlabel('时间 t')
ylabel('计数过程 N(t)')
legend('样本函数 1','样本函数 2','样本函数 3')
W1 = 0;
n = 1;
sigma = 2;
N = 101;
while (n < N)
Z = normrnd(0,sigma);W1 = W1 + Z;
W1Value(n) = W1;
n = n + 1;
end
irt = 0:1:99;
plot(irt,W1Value)
hold on;
W2 = 0;
n = 1;
sigma = 2;
N = 101;
while (n < N)
Z = normrnd(0,sigma);
W2 = W2 + Z;
W2Value(n) = W2;
n = n + 1;
end
irt = 0:1:99;
plot(irt,W2Value)
hold on;
W3 = 0;n = 1;
sigma = 2;
N = 101;
while (n < N)
Z = normrnd(0,sigma);
W3 = W3 + Z;
W3Value(n) = W3;
n = n + 1;
end
irt = 0:1:99;
plot(irt,W3Value)
axis([0 150 -40 40])
title('布朗运动过程仿真结果')
xlabel('时间 t')
ylabel('布朗运动过程 w(t)')
legend('样本函数 1','样本函数 2','样本函数 3')
参考资料:陈建华 基于 MATLAB 的随机过程仿真[J].信息系统工程,2011.
标签:amd 随机过程 空间 参考资料 elseif val clear label legend
原文地址:https://www.cnblogs.com/smallocean/p/10187389.html