| 查看: 718 | 回复: 1 | |||
[求助]
MATLAB的粒子群优化算法恳请大家看看错在
|
|
%%%%%%五杆机构角度力矩曲线%%% function sum_erroeT=f_and_bar1(RR) %clc %clear all %r1=2.366947e+000;r2=1.319752e+000;r3=3.133751e+000;r4=3.421460e+000;thta20=5.837441e-001;K4=1.910935e+003; %r1=2.638433e+000;r2=2.166667e+000;r3=3.617646e+000;r4=3.201909e+000;thta20=1.220969e+000;K4=1.995060e+003; L1=RR(1);L2=RR(2);L3=RR(3);L4=RR(4);L5=RR(5);theta20=RR(6);theta30=RR(7);K1=RR(8);K2=RR(9);K3=RR(10);K4=RR(11); n=360; theta3=zeros(1,n+1);theta4=zeros(1,n+1);theta5=zeros(1,n+1);Tin=zeros(1,n+1); R=[L1,L2,L3,L4,L5]; R=sort(R); %%%初始位置%%% m=(L1^2+L2^2-2*L1*L2*cos(theta20))^(1/2); theta21=acos((L2^2+m^2-L1^2)/(2*L2*m)); n=(L3^2+m^2-2*L3*m*cos(pi-theta20+theta30-theta21))^(1/2); theta41=acos((L4^2+L5^2-n^2)/(2*L4*L5)); theta53=acos((n^2+L5^2-L4^2)/(2*n*L5)); theta52=acos((m^2+n^2-L3^2)/(2*m*n)); theta51=acos((L1^2+m^2-L2^2)/(2*L1*m)); theta50=pi-theta51-theta52-theta53; theta40=2*pi-theta41-theta51-theta52-theta53; %%%%活动位置%%%% zoom1=16*pi/8; dt2=2/180*zoom1; theta1=0*pi/180; dtdt2=1; theta=[theta1 theta20 theta30 theta40 theta50]; theta2(1)=theta20; theta3(1)=theta30; theta4(1)=theta40; theta5(1)=theta50; K5=50000; for n=2:95 [dtdt3,dtdt4,dtdt5]=mfv00111(theta,theta20,theta30,theta40,theta50,L2,L3,L4,L5,K2,K3,K4,K5); % 调用函数计算运动系数 theta2(n)=theta2(n-1)+dtdt2*dt2; theta3(n)=theta3(n-1)+dtdt3*dt2; theta4(n)=theta4(n-1)+dtdt4*dt2; theta5(n)=theta50; % 更新各杆角度 theta=[theta1 theta2(n) theta3(n) theta4(n) theta5(n)]; % 记录角度,共5列,每一列是一个杆的角度 d2t2=dtdt2; d3t2=dtdt3; d4t2=dtdt4; d5t2=dtdt5; % 三个运动系数,计算Tin时需要 % n=n+1; end hold on K5=0; for n=95:360 [dtdt3,dtdt4,dtdt5]=mfv00111(theta,theta20,theta30,theta40,theta50,L2,L3,L4,L5,K2,K3,K4,K5); % 调用函数计算运动系数 theta2(n)=theta2(n-1)+dtdt2*dt2; theta3(n)=theta3(n-1)+dtdt3*dt2; theta4(n)=theta4(n-1)+dtdt4*dt2; theta5(n)=theta5(n-1)+dtdt5*dt2; % 更新各杆角度 theta=[theta1 theta2(n) theta3(n) theta4(n) theta5(n)]; % 记录角度,共5列,每一列是一个杆的角度 d2t2=dtdt2; d3t2=dtdt3; d4t2=dtdt4; d5t2=dtdt5; % 三个运动系数,计算Tin时需要 % n=n+1; end for i=1 Tin(i)=K1*(theta(2)-theta20)+K2*(theta(2)-theta20-theta(3)+theta30).*(1-d3t2)+K3*(theta(4)-theta40-theta(3)+theta30).*(d4t2-d3t2)+K4*(theta(5)-theta50-theta(4)+theta40).*(d5t2-d4t2)+K5*(theta(5)-theta50).*d5t2; end iM=0;kM_sign=0; for m=1:n j=m+1; if Tin(j)<0 kM_sign=1; iM=iM+1; kM(iM)=j; Mthta2(iM)=(j-1)*zoom1/n; dMthta2=Mthta2(iM)-Mthta2(1); if dMthta2>2*pi break end end end T=Tin; if kM_sign==0 sum_erroeT=99000000000000; else a0=0.007446;a1=-0.002295;b1=0.007685;a2=-0.004961;b2=-0.001599;a3=0.0001106;b3=0.001056;a4=-0.0009491;b4=-0.002075; a5=0.002258;b5=0.0005715;a6=-0.001361;b6=0.001003;a7=8.405e-005;b7=-0.0009052;a8=0.0001944;b8=0.0002579;w=1.819; xmax=1.527976897357042; x=0:zoom1/n xmax+0.05);f=a0+a1*cos(w*x)+b1*sin(w*x)+a2*cos(2*w*x)+b2*sin(2*w*x)+a3*cos(3*w*x)+b3*sin(3*w*x)+a4*cos(4*w*x)+b4*sin(4*w*x)+a5*cos(5*w*x)+b5*sin(5*w*x)+a6*cos(6*w*x)+b6*sin(6*w*x)+a7*cos(7*w*x)+b7*sin(7*w*x)+a8*cos(8*w*x)+b8*sin(8*w*x); zkM=length(kM); z=length(f); T_kM=zeros(1,z); if z>1.2*zkM sum_erroeT=99000000000000; else if z>zkM subn=z-zkM; for i_zkM=1:zkM T_kM(i_zkM)=T(kM(i_zkM)); end for i_subn=1:subn T_kM(zkM+i_subn)=f(zkM+i_subn); end else for i_zkM=1:z T_kM(i_zkM)=T(kM(1)+i_zkM-1); end end errorT=zeros(1,z); ErrorT=zeros(1,z); X=0; for k=1:z X=X+(k-1)*zoom1/n; errorT(k)=f(k)-T_kM(k); if X>0.4 ErrorT(k)=300*errorT(k).^4; else ErrorT(k)=errorT(k).^4; end end sum_erroeT=2*sum (ErrorT);%/10000+max(R)+K4/1000; end end end 在用粒子群优化算法优化时总是出现too many input arguments的错误 [ Last edited by haoxuezhe123 on 2012-3-4 at 14:39 ] |
» 猜你喜欢
拟解决的关键科学问题还要不要写
已经有8人回复
最失望的一年
已经有17人回复
为什么nbs上溴 没有产物点出现呢
已经有6人回复
求推荐博导
已经有4人回复
存款400万可以在学校里躺平吗
已经有34人回复
求助一下有机合成大神
已经有4人回复
求推荐英文EI期刊
已经有5人回复
26申博
已经有3人回复
基金委咋了?2026年的指南还没有出来?
已经有10人回复
疑惑?
已经有5人回复
» 本主题相关价值贴推荐,对您同样有帮助:
【PSO】粒子群算法,大家接触多少? Particle Swarm Optimization for everyone
已经有19人回复
求回归方程参数估计的最优化算法matlab代码
已经有9人回复
晶格常数优化
已经有7人回复
怎样用MATLAB计算出图中白色圆形的面积
已经有6人回复
有人学过<神经网络>和《模糊数学》还有《matlab》这三门课吗?名字都好虚幻~
已经有20人回复
【求助】大家看下这个在MATLAB上是什么错?
已经有7人回复
【求助】大家看看,matlab安装过程的截图,找出错
已经有14人回复
【求助】密度矩阵重整化群算法(DMRG)
已经有9人回复
【分享】粒子群算法和遗传算法应用与改进实验框架
已经有42人回复
ppbbo
木虫 (小有名气)
- 应助: 3 (幼儿园)
- 金币: 1823.5
- 红花: 2
- 帖子: 217
- 在线: 69.8小时
- 虫号: 1705097
- 注册: 2012-03-20
- 专业: 信号理论与信号处理
2楼2012-12-09 13:35:10













xmax+0.05);
回复此楼