%粒子群优化法辨识
clear all;close all;
global Ts m u y n
%读取系统时间及输入输出数据
load data_step_io u y;
% global Ts m u1 u2 u3 y n1 n2 n3
% %读取系统时间及输入输出数据
% load data_step_io u1 u2 u3 y;
data_sum=size(y);%读取数据个数
m=data_sum(2);
Ts=6;%设置采样周期
for i=1:m
t(i)=(i-1)*Ts;
end
plot(t,y,':')
hold on;
type = 1; %%设置辨识模型
%% type = 1 K/(Ts+1)^n 一型 psoi_obj_1(V(:,i));
%% type = 2 K/(T1s+1)(T2s+1)(T3s+1) 二型 psoi_obj_2(V(:,i)) ;
%% type = 3 K*e^(-tao*s)/(Ts+1) 三型 psoi_obj_3(V(:,i));
%% type = 4 K/s(Ts+1)^n 三型 psoi_obj_4(V:i);
%% type = 5 ;上述四种模型混合
if type == 1
N=2;%优化参数个数
V_l(1:N)=[-20 10];%置传递函数系数的下限
V_h(1:N)=[1 500]; %置传递函数系数的上限
n=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type == 2
N=5;%优化参数个数
V_l(1:N)=[-20 5 5 5 0];%置传递函数系数的下限
V_h(1:N)=[0 300 300 300 0];%置传递函数系数的上限
n(2)=1;
n(3)=1;
n(4)=1;
end
if type == 3
N=3;%优化参数个数
V_l(1:N)=[-30 5 5];%置传递函数系数的下限
V_h(1:N)=[-15 100 50];%置传递函数系数的上限
n=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type == 4
N=3;%优化参数个数
V_l(1:N)=[-30 5 5]; %置传递函数系数的下限
V_h(1:N)=[-15 100 50];%置传递函数系数的上限
n=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type == 5
if type1 == 1
N1=2;%优化参数个数
V_l1(1:N1)=[-20 10]; %置传递函数系数的下限
V_h1(1:N1)=[1 500]; %置传递函数系数的上限
n1=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type1 == 2
N1=5;%优化参数个数
V_l1(1:N1)=[-20 5 5 5 0];%置传递函数系数的下限
V_h1(1:N1)=[0 300 300 300 0];%置传递函数系数的上限
n1(1)=1;
n1(2)=1;
n1(3)=1;
n1(4)=1;
end
if type1 == 3
N1=3;%优化参数个数
V_l1(1:N1)=[-30 5 5];%置传递函数系数的下限
V_h1(1:N1)=[-15 100 50]; %置传递函数系数的上限
n1=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type1 == 4
N1=3;%优化参数个数
V_l1(1:N1)=[-30 5 5];%置传递函数系数的下限
V_h1(1:N1)=[-15 100 50];%置传递函数系数的上限
n1=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type2 == 1
N2=2;%优化参数个数
V_l2(1:N2)=[-20 10];%置传递函数系数的下限
V_h2(1:N2)=[1 500];%置传递函数系数的上限
n2=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type2 == 2
N2=5;%优化参数个数
V_l2(1:N2)=[-20 5 5 5 0];%置传递函数系数的下限
V_h2(1:N2)=[0 300 300 300 0];%置传递函数系数的上限
n2(1)=1;
n2(2)=1;
n2(3)=1;
n2(4)=1;
end
if type2 == 3
N2=3;%优化参数个数
V_l2(1:N2)=[-30 5 5];%置传递函数系数的下限
V_h2(1:N2)=[-15 100 50];%置传递函数系数的上限
n2=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type2 == 4
N2=3;%优化参数个数
V_l2(1:N2)=[-30 5 5];%置传递函数系数的下限
V_h2(1:N2)=[-15 100 50];%置传递函数系数的上限
n2=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type3 == 1
N3=3;%优化参数个数
V_l3(1:N3)=[-20 10]; %置传递函数系数的下限
V_h3(1:N3)=[1 500];%置传递函数系数的上限
n3=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type3 == 2
N3=5;%优化参数个数
V_l3(1:N3)=[-20 5 5 5 0];%置传递函数系数的下限
V_h3(1:N3)=[0 300 300 300 0];%置传递函数系数的上限
n3(1)=1;
n3(2)=1;
n3(3)=1;
n3(4)=1;
end
if type3 == 3
N3=3;%优化参数个数
%置传递函数系数的下限
V_l3(1:N3)=[-30 5 5];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h3(1:N3)=[-15 100 50];%G(s)=V1/(V2s+1)^V3
n3=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
if type3 == 4
N3=3;%优化参数个数
%置传递函数系数的下限
V_l3(1:N3)=[-30 5 5];%G(s)=V1/(V2s+1)^V3
%置传递函数系数的上限
V_h3(1:N3)=[-15 100 50];%G(s)=V1/(V2s+1)^V3
n3=3;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%自设定阶次n
end
N=N1+N2+N3;
V_l(1:N)=[V_l1 V_l2 V_l3];
V_h(1:N)=[V_h1 V_h2 V_h3];
end
M=50;%粒子个数
S=50;%进化代数
w=0.6;%遗忘因子
c=[0.6 0.6];%学习因子
%置寻优变量初值
V=rand(N,M);
DV=zeros(N,M);
V1=rand(N1,M);
DV1=zeros(N1,M);
V2=rand(N2,M);
DV2=zeros(N2,M);
V3=rand(N3,M);
DV3=zeros(N3,M);
for i=1:M
for j=1:N
V(j,i)=V_l(j)+(V_h(j)-V_l(j))*V(j,i);%%V为N行M列的随机矩阵,每列代表一个粒子,行代表粒子的每个维度
end
for j=1:N1
V1(j,i)=V_l1(j)+(V_h1(j)-V_l1(j))*V1(j,i);%%V为N行M列的随机矩阵,每列代表一个粒子,行代表粒子的每个维度
end
for j=1:N2
V2(j,i)=V_l2(j)+(V_h2(j)-V_l2(j))*V2(j,i);%%V为N行M列的随机矩阵,每列代表一个粒子,行代表粒子的每个维度
end
for j=1:N3
V3(j,i)=V_l3(j)+(V_h3(j)-V_l3(j))*V3(j,i);%%V为N行M列的随机矩阵,每列代表一个粒子,行代表粒子的每个维度
end
if type == 1
[Q(i),y1]=psoi_obj_1(V(:,i));
end
if type == 2
[Q(i),y1]=psoi_obj_2(V(:,i));
end
if type == 3
[Q(i),y1]=psoi_obj_3(V(:,i));
end
if type == 4
[Q(i),y1]=psoi_obj_4(V(:,i));
end
if type == 5
if type1 == 1
[Q1(i),y1]=psoi_obj_1(V1(:,i));
end
if type1 == 2
[Q1(i),y1]=psoi_obj_2(V1(:,i));
end
if type1 == 3
[Q1(i),y1]=psoi_obj_3(V1(:,i));
end
if type1 == 4
[Q1(i),y1]=psoi_obj_4(V1(:,i));
end
if type2 == 1
[Q2(i),y1]=psoi_obj_1(V2(:,i));
end
if type2 == 2
[Q2(i),y1]=psoi_obj_2(V2(:,i));
end
if type2 == 3
[Q2(i),y1]=psoi_obj_3(V2(:,i));
end
if type2 == 4
[Q2(i),y1]=psoi_obj_4(V2(:,i));
end
if type3 == 1
[Q3(i),y1]=psoi_obj_1(V3(:,i));
end
if type3 == 2
[Q3(i),y1]=psoi_obj_2(V3(:,i));
end
if type3 == 3
[Q3(i),y1]=psoi_obj_3(V3(:,i));
end
if type3 == 4
[Q3(i),y1]=psoi_obj_4(V3(:,i));
end
Q(i)=Q1(i)+Q2(i)+Q3(i);
V=[V1 V2 V3];
end
end
Qbi=Q;Vbi=V;
Qbg=Q(1);Vbg=V(:,1);
for i=2:M
if Qbg>Q(i)
Qbg=Q(i);Vbg=V(:,i);
end
end
%迭代计算
for k=1:S
for i=1:M
for j=1:N
DV(j,i)=w*DV(j,i)+c(1)*rand(1)*(Vbi(j,i)-V(j,i))+c(2)*rand(1)*(Vbg(j)-V(j,i));
end
V(:,i)=V(:,i)+DV(:,i);
for j1=1:N
for i1=1:M
if V(j1,i1)<V_l(j1)
V(j1,i1)=V_l(j1);
end
if V(j1,i1)>V_h(j1)
V(j1,i1)=V_h(j1);
end
end
end
if type == 1
[Q(i),y1]=psoi_obj_1(V(:,i));
end
if type == 2
[Q(i),y1]=psoi_obj_2(V(:,i));
end
if type == 3
[Q(i),y1]=psoi_obj_3(V(:,i));
end
if type == 4
[Q(i),y1]=psoi_obj_4(V(:,i));
end
if type == 5
V1=V(1:N1);
V2=V(N1+1:N1+N2);
V3=V(N1+N2+1:N1+N2+N3);
if type1 == 1
[Q1(i),y1]=psoi_obj_1(V1(:,i));
end
if type1 == 2
[Q1(i),y1]=psoi_obj_2(V1(:,i));
end
if type1 == 3
[Q1(i),y1]=
基于粒子群PSO算法系统辨识matlab程序(含多种结构)
需积分: 38 144 浏览量
2019-01-19
19:29:44
上传
评论 30
收藏 4KB ZIP 举报
Process(^_−)
- 粉丝: 10
- 资源: 8
最新资源
- 什么是移动应用开发-关于移动应用开发的相关介绍
- 第二组汇报 PPT.pptx
- 什么是大数据开发-相关介绍-关于大数据开发的相关介绍
- 什么是软件测试-相关介绍-关于软件测试的相关介绍
- 前端开发-什么是前端开发-关于前端开发的一些相关介绍
- Sora AI-关于文生视频的使用场景说明
- suno AI文生视频的相关教程和介绍使用
- 什么是后端开发-关于后端开发的一些小介绍分享
- Jurassic Pack Vol. II Dinosaurs 侏罗纪包卷恐龙二号Unity游戏模型资源unitypackage
- Jurassic Pack Vol. III Dinosaurs 侏罗纪包卷恐龙三号Unity游戏模型资源unitypackag
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈