24小时热门版块排行榜    

查看: 716  |  回复: 1

haoxuezhe123

新虫 (初入文坛)

[求助] 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/nxmax+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 ]
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

ppbbo

木虫 (小有名气)

请问问题解决了吗
2楼2012-12-09 13:35:10
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 haoxuezhe123 的主题更新
信息提示
请填处理意见