声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2756|回复: 8

[编程技巧] 编的控制器报错,请帮助解决,谢谢!

[复制链接]
发表于 2009-7-28 21:46 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
是一个三输入两输出的模糊控制,运行报错。
%定义输入和输出变量及隶属度函数
a=newfis('wenkongqi');
a=addvar(a,'input','e1',[-6 6]);
a=addmf(a,'input',1,'NB','trimf',[-6,-4.5,-3]);
a=addmf(a,'input',1,'NM','trimf',[-4.5,-3,-1.5]);
a=addmf(a,'input',1,'NS','trimf',[-3,-1.5,0]);
a=addmf(a,'input',1,'ZO','trimf',[-1.5,0,1.5]);
a=addmf(a,'input',1,'PS','trimf',[0,1.5,3]);
a=addmf(a,'input',1,'PM','trimf',[1.5,3,4.5]);
a=addmf(a,'input',1,'PB','trimf',[3,4.5,6]);
a=addvar(a,'input','e2',[-6 6]);
a=addmf(a,'input',2,'NB','trimf',[-6,-4.5,-3]);
a=addmf(a,'input',2,'NM','trimf',[-4.5,-3,-1.5]);
a=addmf(a,'input',2,'NS','trimf',[-3,-1.5,0]);
a=addmf(a,'input',2,'ZO','trimf',[-1.5,0,1.5]);
a=addmf(a,'input',2,'PS','trimf',[0,1.5,3]);
a=addmf(a,'input',2,'PM','trimf',[1.5,3,4.5]);
a=addmf(a,'input',2,'PB','trimf',[3,4.5,6]);
a=addvar(a,'output','u',[30 70]);
a=addmf(a,'output',1,'NB','trimf',[-4,-4,-2]);
a=addmf(a,'output',1,'NM','trimf',[-4,-2,0]);
a=addmf(a,'output',1,'NS','trimf',[-4,-2,0]);
a=addmf(a,'output',1,'ZO','trimf',[-2,0,2]);
a=addmf(a,'output',1,'PS','trimf',[0,2,4]);
a=addmf(a,'output',1,'PM','trimf',[0,2,4]);
a=addmf(a,'output',1,'PB','trimf',[2,4,4]);
a=addvar(a,'output','A1',[0.1 0.9]);
a=addmf(a,'output',2,'NB','trimf',[0.1,0.2,0.3]);
a=addmf(a,'output',2,'NM','trimf',[0.2,0.3,0.4]);
a=addmf(a,'output',2,'NS','trimf',[0.3,0.4,0.5]);
a=addmf(a,'output',2,'ZO','trimf',[0.4,0.5,0.6]);
a=addmf(a,'output',2,'PS','trimf',[0.5,0.6,0.7]);
a=addmf(a,'output',2,'PM','trimf',[0.6,0.7,0.8]);
a=addmf(a,'output',2,'PB','trimf',[0.7,0.8,0.9]);
a=addvar(a,'output','A2',[0.1 0.9]);
a=addmf(a,'output',3,'NB','trimf',[0.1,0.2,0.3]);
a=addmf(a,'output',3,'NM','trimf',[0.2,0.3,0.4]);
a=addmf(a,'output',3,'NS','trimf',[0.3,0.4,0.5]);
a=addmf(a,'output',3,'ZO','trimf',[0.4,0.5,0.6]);
a=addmf(a,'output',3,'PS','trimf',[0.5,0.6,0.7]);
a=addmf(a,'output',3,'PM','trimf',[0.6,0.7,0.8]);
a=addmf(a,'output',3,'PB','trimf',[0.7,0.8,0.9]);
%模糊规则矩阵
kk=[1 0 1 7 0 1 1
    2 0 2 6 0 1 1
    3 0 3 5 0 1 1
    4 0 4 4 0 1 1
    5 0 5 3 0 1 1
    6 0 6 2 0 1 1
    7 0 7 1 0 1 1
   
    0 1 1 7 0 1 1
    0 2 2 6 0 1 1
    0 3 3 5 0 1 1
    0 4 4 4 0 1 1
    0 5 5 3 0 1 1
    0 6 6 2 0 1 1
    0 7 7 1 0 1 1
   
    1 1 1 7 1 1 1
    2 2 2 6 6 1 1
    3 3 3 5 5 1 1
    4 4 4 4 4 1 1
    5 5 5 3 3 1 1
    6 6 6 2 2 1 1
    7 7 7 1 1 1 1];
r1=zeros(numel(size(kk)),3);k=1;
for i=1:size(kk,1)
    for j=1:size(kk,2)
        r1(k,:)=[i,j,kk(i,j)];
        k=k+1;
    end
end
[r,s]=size(r1);
r2=ones(r,2);
rulelist=[r1,r2];
a=addrule(a,kk);
%采用模糊控制器的二阶系统仿真
e1=0;e2=0;N=100;
ku1=1;ku2=1;ku3=1;
for k=1:N
    %输入变量变换至论域
    if e1>=6
        e1=6;
    elseif e1<=-6
        e1=-6;
    end
    if e2>=6
        e2=6;
    elseif e2<=-6
        e2=-6;
    end
        %模糊推理,计算出被控对象的控制输入
    in=[e1 e2];
   
    u=ku1*evalfis(in,a);
    A1=ku2*evalfis(in,a);
    A2=ku3*evalfis(in,a);
   
end
错误显示:

Total area is zero in defuzzCentroid() for output 1.
Average of the range of this output variable is used as the output value.
Total area is zero in defuzzCentroid() for output 1.
Average of the range of this output variable is used as the output value.
Total area is zero in defuzzCentroid() for output 1.
Average of the range of this output variable is used as the output value.
Total area is zero in defuzzCentroid() for output 1.
Average of the range of this output variable is used as the output value.
Total area is zero in defuzzCentroid() for output 1.
Average of the range of this output variable is used as the output value.
这是什么原因造成的,给大侠们告知,不胜感谢!
回复
分享到:

使用道具 举报

 楼主| 发表于 2009-8-2 13:52 | 显示全部楼层

求帮助,模糊控制器evalfis函数问题。

求助,如何解决这个问题,谢谢啦!
是一个IF语句,e1不为0,e2不为0,de1不为0,de2不为0
??? Operands to the || and && operators must be convertible to logical scalar values.
Error in ==> wenkongqi3 at 142
    if (~e1==0)&&(~e2==0)&&(~de1==0)&&(~de2==0)

写成这样:
    if (e1~=0)&(e2~=0)&(de1~=0)&(de2~=0)
就不报错了,是不是这样为正确的。

还有一个问题是这样的:我参照以下的例子
ke=30;kd=0.2;ku=1;
num=20;
den=[1.6 4.4 1];
[a1,b,c,d]=tf2ss(num,den);
x=[0;0];%the init  2*1 vector
T=0.01;h=T; %step
N=250;
R=1.5*ones(1,N);

a=newfis('simple');
a=addvar(a,'input','e',[-6,6]);
a=addmf(a,'input',1,'NB','trapmf',[-6,-6,-5,-3]);
a=addmf(a,'input',1,'NS','trapmf',[-5,-3,-2,0]);
a=addmf(a,'input',1,'ZR','trimf',[-2,0,2]);
a=addmf(a,'input',1,'PS','trapmf',[0,2,3,5]);
a=addmf(a,'input',1,'PB','trapmf',[3,5,6,6]);
a=addvar(a,'input','de',[-6,6]);
a=addmf(a,'input',2,'NB','trapmf',[-6 -6 -5 -3]);
a=addmf(a,'input',2,'NS','trapmf',[-5 -3 -2 0]);
a=addmf(a,'input',2,'ZR','trimf',[-2 0 2]);
a=addmf(a,'input',2,'PS','trapmf',[0 2 3 5]);
a=addmf(a,'input',2,'PB','trapmf',[3 5 6 6]);
a=addvar(a,'output','u',[-3,3]);
a=addmf(a,'output',1,'NB','trapmf',[-3 -3 -3 -2]);
a=addmf(a,'output',1,'NS','trimf',[-2 -1 0]);
a=addmf(a,'output',1,'ZR','trimf',[-1 0 1]);
a=addmf(a,'output',1,'PS','trimf',[0 1 2]);
a=addmf(a,'output',1,'PB','trapmf',[2 3 3 3]);

rr=[5 5 4 4 3
    5 4 4 3 3
    4 4 3 3 2
    4 3 3 2 2
    3 3 2 2 1];
r1=zeros(prod(size(rr)),3);k=1;
for i=1:size(rr,1)
    for j=1:size(rr,2)
        r1(k,:)=[i,j,rr(i,j)];
        k=k+1;
    end
end
[r,s]=size(r1);
r2=ones(r,2);
rulelist=[r1,r2];
a=addrule(a,rulelist);

e=0;de=0;


for k=1:N
    e1=ke*e;
    de1=kd*de;
    if e1>=6
        e1=6;
    elseif e1<=-6
        e1=-6;
    end
    if de1>=6
        de1=6;
    elseif de1<=-6
        de1=-6;
    end
    %fuzzy controler
    in=[e1;de1]
    u=ku*evalfis(in,a);
    uu(1,k)=u;
    %under control system
    k0=a1*x+b*u;
    k1=a1*(x+h*k0/2)+b*u;
    k2=a1*(x+h*k1/2)+b*u;
    k3=a1*(x+h*k2)+b*u;
    x=x+(k0+2*k1+2*k2+k3)*h/6;
    y=c*x+d*u;
    yy(1,k)=y;
   
    e1=e;
    e=y-R(1,k);
    de=(e-e1)/T;
end

kk=[1:N]*T;
figure(1);
plot(kk,R,'k',kk,yy,'r');grid on
xlabel('time(s)');ylabel('output');

在我的程序里面,有3个FIS,3个控制量输出,后面是模型,报错在后。
if (e1~=0)&(e2~=0)&(de1~=0)&(de2~=0)
    %输入变量变换至论域
    if e1>=6
        e1=6;
    elseif e1<=-6
        e1=-6;
    end
    if e2>=6
        e2=6;
    elseif e22<=-6
        e2=-6;
    end
    if de1>=6
        de1=6;
    elseif de1<=-6
        de1=-6;
    end
    if de2>=6
        de2=6;
    elseif de2<=-6
        de2=-6;
    end
   
    %模糊推理,计算出被控对象的控制输入
    in1=[e1;e2];
    in2=[e1;de1];
    in3=[e2;de2];

??? Error using ==> vertcat
CAT arguments dimensions are not consistent.
Error in ==> wenkongqi3 at 166
    in1=[e1;e2];
格式是相同的,是什么原因呢?

[ 本帖最后由 海浪语 于 2009-8-2 14:47 编辑 ]
发表于 2009-8-2 14:51 | 显示全部楼层
LZ的版本是多少? 有支援&&? 若没有, 改为&

[ 本帖最后由 ChaChing 于 2009-8-2 15:14 编辑 ]
 楼主| 发表于 2009-8-2 14:56 | 显示全部楼层
谢,我现在用的是2007a,现在是in1=[e1;e2];报错
提示我:??? Error using ==> vertcat
CAT arguments dimensions are not consistent.
Error in ==> wenkongqi3 at 166
    in1=[e1;e2];
不大清楚怎么解决。
发表于 2009-8-2 15:14 | 显示全部楼层

回复 板凳 海浪语 的帖子

检查一下e1及e2的size, 看看in1=[e1;e2];是否合理!
 楼主| 发表于 2009-8-2 15:43 | 显示全部楼层
我这个模糊控制器,是多输入多输出的,但是模糊控制箱里的函数都是二维的,所以我用了3个IF语句判断选择,基本结构和我举得例子一样,只不过例子是1个FIS,我是3个FIS,SIZE应该是相同的,我这里面   
  in1=[e1;e2];
    in2=[e1;de1];
    in3=[e2;de2];
也是对应的
  e11=e1;e1=x7-TIN1;de1=(e1-e11)/i;
    e22=e2;e2=x8-TIN2;de2=(e2-e22)/i;
在考虑怎么解决这个错误,希望能得到你的指点,谢谢。
发表于 2009-8-2 15:56 | 显示全部楼层
模糊控制个人外行! 从报错告知e1及e2不同大小!
LZ可使用debug看看e1及e2的确实大小, 或在报错前一行增加size(e1), size(e2)!
 楼主| 发表于 2009-8-2 16:09 | 显示全部楼层
前面加入一行size(e1), size(e2),运行结果:

ans =

           1       10000


ans =

     1     1

??? Error using ==> vertcat
CAT arguments dimensions are not consistent.

Error in ==> wenkongqi3 at 167
    in1=[e1;e2];
能帮我分析一下吗,谢谢。
发表于 2009-8-2 21:55 | 显示全部楼层
size(e1)=1*10000, size(e2)=1*1, 可以in1=[e1;e2]吗?
看起来好像e1有问题, 不应该为1*10000? 是吗?
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-22 07:03 , Processed in 0.064230 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表