clc
clear
L = 500;
R = 1;
Q = 100*eye(4);
M1 = 0;
t = [-2 -1 1 2];
z = zeros(4,L);
theta1 = zeros(5,L);
theta2 = zeros(5,L);
theta3 = zeros(5,L);
theta4 = zeros(5,L);
P = 10^6*eye(5);
%%
%生成噪声
r = rand(1,L);
for i = 1:L
x1 = i/L;
F_w = 4*x1^3 - 3*x1^4;
y1(i) = F_w;
for j = 1:L
temp(j) = abs(y1(i) - r(j));
end
[a,b] = min(temp);
location(i) = b;
end
w = r(location);
w = w(randperm(length(w)));
% bar(w);
%%
x(L) = 0;
for k = 1:L
if k<=200
u(k) = sin(k);
x(k+1) = x(k)*sin(x(k))+u(k)+x(k)*w(k);
y(k) = 0.5*x(k);
else if k<=205
u(k) = sin(k);
end
x(k+1) = x(k)*sin(x(k))+u(k)+x(k)*w(k);
y(k) = 0.5*x(k);
[f,xi] = ksdensity(y,'width',0.1);
% [f,xi,l] = ksdensity(y);
for i=1:4
M1 = 1;
for j =1:20
M(k,i) = M1 + t(i).^j*xi.^j*f'*0.1/factorial(j);
% M(k,i) = M1 + t(i).^j*xi.^j*f'*l/factorial(j);
M1 = M(k,i);
end
end
if k>=205
phi = log(M);
z = [phi(:,1),phi(:,2),phi(:,3),phi(:,4)];
h(:,k) = [z(k-1,1),z(k-1,2),z(k-1,3),z(k-1,4),u(k-1)]';
K = P*h(:,k)/(1+h(:,k)'*P*h(:,k));
theta1(:,k) = theta1(:,k-1)+K*(phi(k,1)-h(:,k)'*theta1(:,k-1));
theta2(:,k) = theta2(:,k-1)+K*(phi(k,2)-h(:,k)'*theta2(:,k-1));
theta3(:,k) = theta3(:,k-1)+K*(phi(k,3)-h(:,k)'*theta3(:,k-1));
theta4(:,k) = theta4(:,k-1)+K*(phi(k,4)-h(:,k)'*theta4(:,k-1));
P = (eye(5)-K*h(:,k)')*P;
A = [theta1(1:4,k),theta2(1:4,k),theta3(1:4,k),theta4(1:4,k)];
B = [theta1(5,k);theta2(5,k);theta3(5,k);theta4(5,k)];
sigma = 1/(2*(R+B'*Q*B));
% sigma =0.9;
KK = B'*Q*A;
u(k+1) = -sigma*KK*(z(k,:))';
end
end
end
z(1:200,:) = 0;
figure(1)
plot(y);
title('输出yk');
figure(2)
plot(u);
title('输入uk');
% figure(3)
% plot(z);
% xlabel('k')
% legend('z1','z2','z3','z4')
% xx = 1:L;
% figure(4)
% set(gca,'XDir','reverse','YDir','reverse','ZDir','reverse');
% mesh(-t,1:L,z)
% set(gca,'Yaxislocation','left')
% figure(5)
% plot(xi,f);
A
B
KK
u(k+1)
tic
toc
k200_随机系统控制_couldkt5_pdf控制_输出分布系统_
5星 · 超过95%的资源 98 浏览量
2021-10-02
07:56:05
上传
评论 2
收藏 1KB ZIP 举报
呼啸庄主
- 粉丝: 74
- 资源: 4702
评论3