24小时热门版块排行榜    

查看: 787  |  回复: 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 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 奇怪,两个人的filecode固定段从头到尾一模一样 +5 布布和一二 2026-08-10 5/250 2026-08-11 09:17 by xiaruohan
[基金申请] 帮忙看看fileCode +6 wwncly 2026-08-10 11/550 2026-08-11 09:14 by xiaruohan
[基金申请] FileCode能看出啥? +7 要乐观耀哥 2026-08-10 16/800 2026-08-11 08:18 by wmfsnow
[基金申请] 基金中了 +15 laoda193707 2026-08-06 15/750 2026-08-11 00:11 by jiafei2190
[基金申请] filecode +8 documentary 2026-08-10 8/400 2026-08-10 19:20 by loufangrui
[基金申请] 确定了,国自然21号放榜 +6 布布和一二 2026-08-10 7/350 2026-08-10 19:15 by 2000zf36392
[基金申请] 综述论文作为代表作会不会影响评审专家的印象分? +10 yufeiwaner 2026-08-09 11/550 2026-08-10 18:47 by yufeiwaner
[基金申请] 关于代码变化问题,想知道的进来 +17 且听虎啸 2026-08-07 24/1200 2026-08-10 18:35 by zhangduo2008
[基金申请] 关于Filecode分析方法 +3 majunge000 2026-08-10 3/150 2026-08-10 15:46 by lch2012
[基金申请] 8月时间戳变的,举个手。玩一下,释放压力 +11 archvillain 2026-08-04 13/650 2026-08-10 14:41 by seekfind
[基金申请] 据悉今年马上要出结果了 +7 瞬息宇宙 2026-08-10 8/400 2026-08-10 12:42 by Vivilian
[基金申请] 2026国自然放榜时间 +9 布布和一二 2026-08-08 9/450 2026-08-10 11:22 by xxxx2020
[基金申请] 这样的filecode谁见过 +11 布布和一二 2026-08-08 22/1100 2026-08-10 11:10 by wmfsnow
[基金申请] filecode与中标关系的预测 +5 布布和一二 2026-08-07 5/250 2026-08-09 16:15 by 袁向阳007
[基金申请] fileCode有新解读? +10 Tide man 2026-08-08 18/900 2026-08-09 12:55 by 仁砚薪传
[基金申请] 关于filecode,很负责任的告诉大家 +6 爱看书的可乐 2026-08-08 7/350 2026-08-08 22:13 by a_niu
[基金申请] 国基金的申报应该改成非等额制,评价高的钱多评价低的钱少,但是增加资助率 +7 a089 2026-08-07 7/350 2026-08-08 18:05 by gltch
[基金申请] filecode变化情况 +6 布布和一二 2026-08-07 22/1100 2026-08-07 14:45 by 且听虎啸
[基金申请] filecode +8 布布和一二 2026-08-06 11/550 2026-08-06 20:41 by tangpu318
[基金申请] 影响面上的因素 +8 布布和一二 2026-08-05 11/550 2026-08-06 10:41 by 宝贝虫子
信息提示
请填处理意见