该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
程序如下
%%六种板形缺陷
y=-1:0.2:1;%残余应力数目(横向)
p1=y;%左边浪
p2=-p1;%右边浪
p3=3*(y.^2)/2-0.5;%中间浪
p4=-p3;%双边浪
p5=0.125*(35*(y.^4)-30*(y.^2)+3);%四分浪
p6=-p5;%边中浪
pall=[p1;p2;p3;p4;p5;p6];
fg1=figure('numbertitle','off','name','六种标准板形缺陷')
subplot(2,2,1);
plot(y,p1,y,p2);title('一次板形');text(1,1,'左边浪');text(1,-1,'右边浪');xlabel('板宽坐标');ylabel('残余应力');
subplot(2,2,2);
plot(y,p3,y,p4);title('二次板形');text(1,1,'中间浪');text(1,-1,'双边浪');xlabel('板宽坐标');ylabel('残余应力');
subplot(2,2,3);
plot(y,p5,y,p6);title('四次板形');text(1,1,'四分浪');text(1,-1,'边中浪');xlabel('板宽坐标');ylabel('残余应力');
eo1=2*rand(200,3)-1;%样本输出
for i=1:200
eo(i,:)=eo1(i,:)/(abs(eo1(i,1))+abs(eo1(i,2))+abs(eo1(i,3)));%板形参数
end
[row,col]=size(eo);
ei=[];%训练样本
for k=1:row
eil(k,:)=eo(k,1)*p1+eo(k,2)*p3+eo(k,3)*p5;%混合板形参数
end
for z=1:row
for i=1:6
ei(z,i)=sqrt(sum((eil(z,:)-pall(i,:)).^2));%欧式距离
end
eo2=eo1'
ei1=ei'
end
%%BP神经网络学习
p_train=ei';%训练数据输入
outputdata=eo(1:120,:)';%训练数据输出
[inputdata,ps1]=mapminmax(p_train);%归一化处理
net=newff(minmax(inputdata),[13 3],{'tansig','purelin'});%创建网络
net.trainParam.epochs=1000;%训练步数
net.trainParam.goal=0.0002;
net=train(net,inputdata(:,1:120),outputdata);%开始训练
%delete('net2.mat');
save net2 net;%保存网络
%%检验网络
p_test=inputdata(:,1:120);
T_test=sim(net,p_test);
error2=eo(1:120,:)-T_test';
%%仿真测试示例
s_test=inputdata(:,121);
%fg2=figure('numbertitle','off','name','待识别的板形残余应力信号图');
%plot(y,ei1(121,;));title('待识别板形信号','fontsize',25);xlabel('板宽坐标','fontsize',15);ylabel('残余应力','fontsize',15);grid;
answer=sim(net,s_test)';
fg3=figure('numbertitle','off','name','系统板形缺陷识别结果');
subplot(2,2,1);
if answer(1,1)>0
plot(y,answer(1,1)*p1);xlabel('板宽坐标','fontsize',10);ylabel('残余应力','fontsize',10);grid;title(['左边浪隶属度:' num2str(answer(1,1))]);
plot(y,answer(1,1)*p1);xlabel('板宽坐标','fontsize',10);ylabel('残余应力','fontsize',10);grid;title(['右边浪隶属度:' num2str(answer(1,1))]);
end
if answer(1,1)==0
plot(y,answer(1,1)*p1);xlabel('板宽坐标','fontsize',10);ylabel('残余应力','fontsize',10);grid;title('无一次成分');
end
subplot(2,2,2);
if answer(1,2)>0
plot(y,answer(1,2)*p3);xlabel('板宽坐标','fontsize',10);ylabel('残余应力','fontsize',10);grid;title(['中间浪隶属度:' num2str(answer(1,2))]);
else
plot(y,answer(1,2)*p3);xlabel('板宽坐标','fontsize',10);ylabel('残余应力','fontsize',10);grid;title(['双边浪隶属度:' num2str(answer(1,2))]);
end
if answer(1,2)==0
plot(y,answer(1,2)*p3);xlabel('板宽坐标','fontsize',10);ylabel('残余应力','fontsize',10);grid;title('无二次成分');
end
subplot(2,2,3);
if answer(1,3)>0
plot(y,answer(1,3)*p5);xlabel('板宽坐标','fontsize',10);ylabel('残余应力','fontsize',10);grid;title(['四分浪隶属度:' num2str(answer(1,3))]);
else
plot(y,answer(1,3)*p5);xlabel('板宽坐标','fontsize',10);ylabel('残余应力','fontsize',10);grid;title(['边中浪隶属度:' num2str(answer(1,3))]);
end
if answer(1,3)==0
plot(y,answer(1,3)*p5);xlabel('板宽坐标','fontsize',10);ylabel('残余应力','fontsize',10);grid;title('无四次成分');
end
error22=eo(121,:)-answer;
fg4=figure('numbertitle','off','name','系统板形缺陷识别结果对比');
plot(y,answer(1,1)*p1+answer(1,2)*p3+answer(1,3)*p5,'r',y,ei1(121,:),'b');title('测试结果对比','fontsize',25);xlabel('板宽坐标','fontsize',15);ylabel('残余应力','fontsize',15);grid;
legend('识别结果','待识别板形');