• 基于PSO粒子群优化的汽车刹车稳定性数据matlab仿真与分析


    欢迎订阅《FPGA学习入门100例教程》、《MATLAB学习入门100例教程

    目录

    一、理论基础

    二、核心程序

    三、测试结果


    一、理论基础

    刹车类别A

    温度1

    测试1

    测试2

    .......

    测试n

    温度3

    测试1

    测试2

    .......

    测试n

    .......

    .......

    温度N

    测试1

    测试2

    .......

    测试n

            每次测试的温度间隔,根据实际操作的可行性,来选择。这个无所谓,从里面看到温度从20多度到60度,如果条件允许,可以再将温度扩展一下。即测试的温度范围再大点。然后,对于同一个温度,测试次数的确定,如果你每次测试的数值差别较大,那么测试次数最好多点,如果每次测试的差别不大,那么测试20次就够了。

          粒子群优化(PSO)算法是通过模拟鸟群觅食过程中的迁徙和群聚行为而提出的一种基于群体智能的全局随机搜索算法。PSO是将群体(swarm)中的个体看作是在D维搜索空间中没有质量和体积的粒子(particle),每个粒子以一定的速度在解空间运动,并向自身历史最佳位置pbest和邻域历史最佳位置聚集,实现对候选解的进化。

           PSO从这种模型中得到启示并用于解决优化问题。PSO中,每个优化问题的潜在解都是搜索空间中的一只鸟,称之为粒子。所有的粒子都有一个由被优化的函数决定的适值( fitness value),每个粒子还有一个速度决定它们飞翔的方向和距离。然后粒子们就追随当前的最优粒子在解空间中搜索。

           PSO初始化为一群随机粒子,然后通过迭代找到最优解。在每一次迭代中,粒子通过跟踪两个极值来更新自己;第一个就是粒子本身所找到的最优解,这个解称为个体极值;另一个极值是整个种群目前找到的最优解,这个极值是全局极值。另外也可以不用整个种群而只是用其中一部分作为粒子的邻居,那么在所有邻居中的极值就是局部极值。

    二、核心程序

    1. ................................................................
    2. parameter;
    3. ishow = (get(handles.checkbox1,'Value'));
    4. if choice == 1
    5. L2 = func_anti_noise(L1,T1);
    6. else
    7. L2 = func_anti_noise(L1,T2);
    8. end
    9. hold off;
    10. axes(handles.axes4);
    11. color_table;
    12. for i = 1:len1
    13. str = colors{i};
    14. plot(L2(i,:),str);
    15. hold on;
    16. end
    17. if ishow == 1
    18. figure;
    19. color_table;
    20. for i = 1:len1
    21. str = colors{i};
    22. plot(L2(i,:),str);
    23. hold on;
    24. end
    25. title('Leaks anti noise');
    26. end
    27. % --- Executes on button press in pushbutton4.
    28. function pushbutton4_Callback(hObject, eventdata, handles)
    29. % hObject handle to pushbutton4 (see GCBO)
    30. % eventdata reserved - to be defined in a future version of MATLAB
    31. % handles structure with handles and user data (see GUIDATA)
    32. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%多项式拟合%%%%%%%%%%%
    33. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%多项式拟合%%%%%%%%%%%
    34. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%多项式拟合%%%%%%%%%%%
    35. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%多项式拟合%%%%%%%%%%%
    36. parameter;
    37. ishow = (get(handles.checkbox1,'Value'));
    38. KK = str2num(get(handles.edit1,'String'));
    39. if choice == 1
    40. [y1,x1,y0,x0,P1fit] = func_fit_means(T1,L2,KK);
    41. else
    42. [y1,x1,y0,x0,P1fit] = func_fit_means(T2,L2,KK);
    43. end
    44. hold off;
    45. axes(handles.axes5);
    46. plot(x0,y0,'o');
    47. hold on;
    48. plot(x1,y1,'r','LineWidth',1);
    49. hold on;
    50. if ishow == 1
    51. figure;
    52. plot(x0,y0,'o');
    53. hold on;
    54. plot(x1,y1,'r','LineWidth',1);
    55. hold on;
    56. title('多项式拟合曲线');
    57. end
    58. %计算拟合误差
    59. err1 = func_error(y0,x0,y1,x1);
    60. set(handles.edit2,'string',num2str(err1));
    61. % --- Executes on button press in pushbutton5.
    62. function pushbutton5_Callback(hObject, eventdata, handles)
    63. % hObject handle to pushbutton5 (see GCBO)
    64. % eventdata reserved - to be defined in a future version of MATLAB
    65. % handles structure with handles and user data (see GUIDATA)
    66. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最大值多项式拟合%%%%%%%%%%%
    67. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最大值多项式拟合%%%%%%%%%%%
    68. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最大值多项式拟合%%%%%%%%%%%
    69. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最大值多项式拟合%%%%%%%%%%%
    70. parameter;
    71. ishow = (get(handles.checkbox1,'Value'));
    72. KK = str2num(get(handles.edit1,'String'));
    73. if choice == 1
    74. [y1max,x1max,y0max,x0max,P1max] = func_fit_max(T1,L2,KK);
    75. else
    76. [y1max,x1max,y0max,x0max,P1max] = func_fit_max(T2,L2,KK);
    77. end
    78. hold off;
    79. axes(handles.axes5);
    80. plot(x0,y0,'o');
    81. hold on;
    82. plot(x1,y1,'r','LineWidth',1);
    83. hold on;
    84. plot(x1max,y1max,'g','LineWidth',1);
    85. hold on;
    86. if ishow == 1
    87. figure;
    88. plot(x0,y0,'o');
    89. hold on;
    90. plot(x1,y1,'r','LineWidth',1);
    91. hold on;
    92. plot(x1max,y1max,'g','LineWidth',1);
    93. hold on;
    94. title('多项式拟合曲线');
    95. end
    96. function pushbutton6_Callback(hObject, eventdata, handles)
    97. % hObject handle to pushbutton6 (see GCBO)
    98. % eventdata reserved - to be defined in a future version of MATLAB
    99. % handles structure with handles and user data (see GUIDATA)
    100. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最小值多项式拟合%%%%%%%%%%%
    101. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最小值多项式拟合%%%%%%%%%%%
    102. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最小值多项式拟合%%%%%%%%%%%
    103. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%最小值多项式拟合%%%%%%%%%%%
    104. parameter;
    105. ishow = (get(handles.checkbox1,'Value'));
    106. KK = str2num(get(handles.edit1,'String'));
    107. if choice == 1
    108. [y1min,x1min,y0min,x0min,P1min] = func_fit_min(T1,L2,KK);
    109. else
    110. [y1min,x1min,y0min,x0min,P1min] = func_fit_min(T2,L2,KK);
    111. end
    112. hold off;
    113. axes(handles.axes5);
    114. plot(x0,y0,'o');
    115. hold on;
    116. plot(x1,y1,'r','LineWidth',1);
    117. hold on;
    118. plot(x1max,y1max,'g','LineWidth',1);
    119. hold on;
    120. plot(x1min,y1min,'m','LineWidth',1);
    121. hold on;
    122. if ishow == 1
    123. figure;
    124. plot(x0,y0,'o');
    125. hold on;
    126. plot(x1,y1,'r','LineWidth',1);
    127. hold on;
    128. plot(x1max,y1max,'g','LineWidth',1);
    129. hold on;
    130. plot(x1min,y1min,'m','LineWidth',1);
    131. hold on;
    132. title('多项式拟合曲线');
    133. end
    134. % --- Executes on button press in pushbutton7.
    135. function pushbutton7_Callback(hObject, eventdata, handles)
    136. % hObject handle to pushbutton7 (see GCBO)
    137. % eventdata reserved - to be defined in a future version of MATLAB
    138. % handles structure with handles and user data (see GUIDATA)
    139. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%PSO优化拟合%%%%%%%%%%%
    140. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%PSO优化拟合%%%%%%%%%%%
    141. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%PSO优化拟合%%%%%%%%%%%
    142. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%PSO优化拟合%%%%%%%%%%%
    143. parameter;
    144. ishow = (get(handles.checkbox1,'Value'));
    145. KK = str2num(get(handles.edit1,'String'));
    146. %进行PSO优化
    147. [V_score2,PP2] = func_pso(P1fit,x1,y0,x0);
    148. ypso = polyval(PP2,x1);
    149. hold off;
    150. axes(handles.axes6);
    151. plot(V_score2,'Linewidth',2);
    152. hold off;
    153. axes(handles.axes7);
    154. plot(x0,y0,'o');
    155. hold on;
    156. plot(x1,y1,'r','LineWidth',1);
    157. hold on;
    158. plot(x1max,y1max,'g','LineWidth',1);
    159. hold on;
    160. plot(x1min,y1min,'m','LineWidth',1);
    161. hold on;
    162. plot(x1,ypso,'k--','LineWidth',2);
    163. hold on;
    164. if ishow == 1
    165. figure;
    166. subplot(121);
    167. plot(V_score2,'Linewidth',2);
    168. xlabel('迭代次数');
    169. ylabel('拟合误差优化过程');
    170. subplot(122);
    171. plot(x0,y0,'o');
    172. hold on;
    173. plot(x1,y1,'r','LineWidth',1);
    174. hold on;
    175. plot(x1max,y1max,'g','LineWidth',1);
    176. hold on;
    177. plot(x1min,y1min,'m','LineWidth',1);
    178. hold on;
    179. plot(x1,ypso,'k--','LineWidth',2);
    180. hold on;
    181. title('多项式拟合曲线');
    182. legend('实际测量值','均值拟合曲线','最大测量值拟合曲线','最小测量值拟合曲线','优化后拟合曲线');
    183. end
    184. err2 = func_error(y0,x0,ypso,x1);
    185. set(handles.edit3,'string',num2str(err2));
    186. % --- Executes on button press in pushbutton8.
    187. function pushbutton8_Callback(hObject, eventdata, handles)
    188. % hObject handle to pushbutton8 (see GCBO)
    189. % eventdata reserved - to be defined in a future version of MATLAB
    190. % handles structure with handles and user data (see GUIDATA)
    191. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%统计量计算%%%%%%%%%%%
    192. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%统计量计算%%%%%%%%%%%
    193. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%统计量计算%%%%%%%%%%%
    194. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%统计量计算%%%%%%%%%%%
    195. parameter;
    196. %计算均值和方差,将这两个计算结果存放到四个变量的后两位
    197. for i = 1:size(T1,1)
    198. %计算均值
    199. E1(i) = mean(T1(i,:));
    200. E2(i) = mean(T2(i,:));
    201. E3(i) = mean(P1(i,:));
    202. E4(i) = mean(L2(i,:));
    203. %计算标准差
    204. D1(i) = std(T1(i,:));
    205. D2(i) = std(T2(i,:));
    206. D3(i) = std(P1(i,:));
    207. D4(i) = std(L2(i,:));
    208. %计算方差
    209. V1(i) = var(T1(i,:));
    210. V2(i) = var(T2(i,:));
    211. V3(i) = var(P1(i,:));
    212. V4(i) = var(L2(i,:));
    213. end
    214. figure(10);
    215. plot(E1,E4,'b-o');
    216. hold on;
    217. plot(E1,D4,'r-o');
    218. hold on;
    219. plot(E1,V4,'k-o');
    220. legend('均值','标准差','方差');
    221. fid = fopen('statistics.txt','wt');
    222. fprintf(fid,'均值 标准差 方差\n');
    223. for i = 1:length(E4)
    224. fprintf(fid,'%f ',E4(i));
    225. fprintf(fid,'%f ',D4(i));
    226. fprintf(fid,'%f ',V4(i));
    227. fprintf(fid,'\n');
    228. end
    229. fclose(fid);
    230. % --- Executes on button press in pushbutton9.
    231. function pushbutton9_Callback(hObject, eventdata, handles)
    232. % hObject handle to pushbutton9 (see GCBO)
    233. % eventdata reserved - to be defined in a future version of MATLAB
    234. % handles structure with handles and user data (see GUIDATA)
    235. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%拟合统计分析%%%%%%%%%%%
    236. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%拟合统计分析%%%%%%%%%%%
    237. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%拟合统计分析%%%%%%%%%%%
    238. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%拟合统计分析%%%%%%%%%%%
    239. parameter;
    240. ishow = (get(handles.checkbox1,'Value'));
    241. hold off;
    242. axes(handles.axes8);
    243. plot(x0,y0,'o');
    244. hold on;
    245. plot(x1,ypso,'k--','LineWidth',2);
    246. hold on;
    247. %找到最接近0的温度
    248. Best_tmp = 0;
    249. Ind = 0;
    250. for i = 2:length(ypso)-1
    251. if ypso(i-1) < 0 & ypso(i)>=0
    252. Best_tmp = x1(i);
    253. Ind = i;
    254. end
    255. end
    256. plot(x1(Ind),-4:0.01:8,'r','LineWidth',1);
    257. hold on;
    258. plot(x1,ypso(Ind),'r','LineWidth',1);
    259. %根据统计量分析
    260. %找到均值最小的值
    261. Tmpes = abs(E4);
    262. [V,I] = sort(Tmpes);
    263. Best_Team_mean = I(1);
    264. %找到均值最小的值
    265. Tmpes = abs(D4);
    266. [V,I] = sort(Tmpes);
    267. Best_Team_std = I(1);
    268. if ishow == 1
    269. figure(11);
    270. subplot(121);
    271. plot(x0,y0,'o');
    272. hold on;
    273. plot(x1,ypso,'k--','LineWidth',2);
    274. hold on;
    275. plot(x1(Ind),-4:0.01:8,'r','LineWidth',1);
    276. hold on;
    277. plot(x1,ypso(Ind),'r','LineWidth',1);
    278. axis square;
    279. subplot(122)
    280. plot(E1(Best_Team_mean),E4(Best_Team_mean),'--rs','MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10);
    281. hold on;
    282. plot(E1,E4,'b-o');
    283. hold on;
    284. plot(E1(Best_Team_std),D4(Best_Team_std),'--rs','MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',10);
    285. hold on;
    286. plot(E1,D4,'k-o');
    287. hold on;
    288. axis square;
    289. legend('均值','标准差');
    290. end
    291. if Best_Team_mean == Best_Team_std
    292. msgbox(['最稳定温度为:',num2str(Best_tmp),' 对应的测试组为:',num2str(Best_Team_mean)]);
    293. else
    294. msgbox(['最稳定温度为:',num2str(Best_tmp),' 对应的测试组为:',num2str(Best_Team_mean),' 和 ',num2str(Best_Team_std)]);
    295. end

    三、测试结果

     1:显示EXCEL中的数据,将EXCEL导入MATLAB,然后显示出其中的数据:

     

    2:3:显示两个温度和泄漏之间对应关系图,这个是根据样本直接显示的

    4:显示多个LEAK的样本值:

    5:去掉LEAK样本中的一些异常采样点:

     

    6:多项式拟合效果显示:

    7:粒子群优化后的误差收敛曲线

    8:粒子群优化后的多项式拟合效果:

    9:最后的稳定性分析结果:

    左图是根据优化拟合结果,得到实际中最有可能为稳定区域的温度值,如上面的对话框为31.43.

    但是这个在实际中可能没法测试到。

    所以上图中右图就是表示的这个情况,通过均值和方差最小化,得到测试组13和14两个测试温度区域为最佳的区域。

    通过分析,

    在GUI上的数据显示区域,会自动对最佳的数据测试组显示the best的字样。

    A28-13

  • 相关阅读:
    【Rust 笔记】14-集合(上)
    ubuntu非源码安装 openCV
    Monaco Editor教程(十六):缩略图minimap的配置详解
    【C语言】数据的存储_数据类型:浮点型存储
    HTTP协议及Servlet类笔记
    软件加密系统Themida应用程序保护指南(九):通过命令行进行保护
    Spring Boot : ORM 框架 JPA 与连接池 Hikari
    职场人一起进阶吧(内附技术人进阶路径、Java开源项目完整推荐等)
    【文件系统】Linux文件系统的基本存储机制
    Android修行手册 - Toolbar搜索联动以及各种监听和小技巧
  • 原文地址:https://blog.csdn.net/ccsss22/article/details/127895045