求助~~~大神们求指教
时间:10-02
整理:3721RD
点击:
我编写了一个关于三容水箱液位模糊RBF的程序,可是结果是错的,个人找不到原因,求指教啊!
clear all;
close all;
r=100; % set value
ts=0.001;
s=200;
a=3;
y1=20;
y2=30;
y3=200;kp=19;
ki=4.04;
kd=30;
kmax=100;
k(1)=kmax*rand(1);
ku(1)=0;
%%%%%%%%%%%%%%%%%%%%
h1(1)=200*rand(1);
h2(1)=200*rand(1);
h3(1)=200*rand(1);
e(1)=r-h3(1);
e_1=e(1);
sum_e=0;
b=15*ones(7,1);
b_1=b;
b_2=b_1;
c=[-20 -12 -6 0 6 12 20;-20 -12 -6 0 6 12 20];
c_1=c;
c_2=c_1;
w=10*rands(49,1);%%%%%%%?
w_1=w;
w_2=w_1;
xite=0.30;
alfa=0.05;
time(1)=1; % set time
for n=2:1:1000
time(n)=n;
k(n)=k(n-1)+ku(n-1);
if k(n)<0
k(n)=0;
end
if k(n)>kmax
k(n)=kmax;
end
if ((h1(n-1)<5)|(h2(n-1)<5))
k(n)=kmax;
end
if ((h1(n-1)>190)|(h2(n-1)>190)) % &&&&&&
k(n)=0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%% the model %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
q1=a*k(n);
q2=y1*sqrt(h1(n-1));
q3=y2*sqrt(h2(n-1));
q4=y3*abs(sin(n*0.3));
if (h3(n-1)==0)|(h3(n-1)<0)
q4=0;
end
h11=(q1-q2)/s;
h21=(q2-q3)/s;
h31=(q3-q4)/s;
h1(n)=h1(n-1)+h11;
h2(n)=h2(n-1)+h21;
h3(n)=h3(n-1)+h31;
e(n)=r-h3(n);
%%%%%%%%%%%%%%%%%%%%%%%%%%% the rules %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if h1(n)<0
h1(n)=0;
end
if h1(n)>200
h1(n)=200;
end
if h2(n)<0
h2(n)=0;
end
if h2(n)>200
h2(n)=200;
end
if h3(n)<0
h3(n)=0;
end
if h3(n)>200
h3(n)=200;
end
%%%%%%%%%%%%%%%%%%%%%%%% the controller %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%?xxxx!
x=[r,e(n)];%%%%%%%%r?ku?
f1=x;
for i=1:2
for j=1:7
net2(i,j)=-(f1(i)-c(i,j))^2/b(j)^2;
end
end
for i=1:2
for j=1:7
f2(i,j)=exp(net2(i,j));
end
end
for j=1:7
m1(j)=f2(1,j);
m2(j)=f2(2,j);
end
for i=1:7
for j=1:7
ff3(i,j)=m2(i)*m1(j);
end
end
f3=[ff3(1,:),ff3(2,:),ff3(3,:),ff3(4,:),ff3(5,:),ff3(6,:),ff3(7,:)];
f4=w_1'*f3';
ym(n)=f4;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sum_e=sum_e+e(n)*ts;
kup(n)=kp*e(n)+ki*sum_e+kd*(e(n)-e_1)/ts;
ku(n)=kup(n)+ym(n);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
e(n)=h3(n)-ym(n);
d_w=0*w_1;
for j=1:49
d_w(j)=xite*e(n)*f3(j);
end
w=w_1+d_w+alfa*(w_1-w_2);
delta2=-e(n)*w'*f3';
d_b=0*b_1;
for j=1:7
d_b(j)=xite*delta2*2*((x(1)-c(1,j)^2)*b(j)^-3);
end
b=b_1+d_b+alfa*(b_1-b_2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d_c=0*c_1;
for i=1:2
for j=1:7
d_c(i,j)=-xite*delta2*2*(x(i)-c(i,j))*b(j)^-2;
end
end
c=c_1+d_c+alfa*(c_1-c_2);
u_1=ku(n);
y_1=h3(n);
w_2=w_1;
w_1=w;
c_2=c_1;
c_1=c;
b_2=b_1;
b_1=b;
end
figure(1);
plot(time,h3,'r',time,r,'b');
xlabel('time(s)');ylabel('Approaching');
figure(2);
plot(time,h3-r,'r');
xlabel('time(s)');ylabel('Approaching error');
clear all;
close all;
r=100; % set value
ts=0.001;
s=200;
a=3;
y1=20;
y2=30;
y3=200;kp=19;
ki=4.04;
kd=30;
kmax=100;
k(1)=kmax*rand(1);
ku(1)=0;
%%%%%%%%%%%%%%%%%%%%
h1(1)=200*rand(1);
h2(1)=200*rand(1);
h3(1)=200*rand(1);
e(1)=r-h3(1);
e_1=e(1);
sum_e=0;
b=15*ones(7,1);
b_1=b;
b_2=b_1;
c=[-20 -12 -6 0 6 12 20;-20 -12 -6 0 6 12 20];
c_1=c;
c_2=c_1;
w=10*rands(49,1);%%%%%%%?
w_1=w;
w_2=w_1;
xite=0.30;
alfa=0.05;
time(1)=1; % set time
for n=2:1:1000
time(n)=n;
k(n)=k(n-1)+ku(n-1);
if k(n)<0
k(n)=0;
end
if k(n)>kmax
k(n)=kmax;
end
if ((h1(n-1)<5)|(h2(n-1)<5))
k(n)=kmax;
end
if ((h1(n-1)>190)|(h2(n-1)>190)) % &&&&&&
k(n)=0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%% the model %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
q1=a*k(n);
q2=y1*sqrt(h1(n-1));
q3=y2*sqrt(h2(n-1));
q4=y3*abs(sin(n*0.3));
if (h3(n-1)==0)|(h3(n-1)<0)
q4=0;
end
h11=(q1-q2)/s;
h21=(q2-q3)/s;
h31=(q3-q4)/s;
h1(n)=h1(n-1)+h11;
h2(n)=h2(n-1)+h21;
h3(n)=h3(n-1)+h31;
e(n)=r-h3(n);
%%%%%%%%%%%%%%%%%%%%%%%%%%% the rules %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if h1(n)<0
h1(n)=0;
end
if h1(n)>200
h1(n)=200;
end
if h2(n)<0
h2(n)=0;
end
if h2(n)>200
h2(n)=200;
end
if h3(n)<0
h3(n)=0;
end
if h3(n)>200
h3(n)=200;
end
%%%%%%%%%%%%%%%%%%%%%%%% the controller %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%?xxxx!
x=[r,e(n)];%%%%%%%%r?ku?
f1=x;
for i=1:2
for j=1:7
net2(i,j)=-(f1(i)-c(i,j))^2/b(j)^2;
end
end
for i=1:2
for j=1:7
f2(i,j)=exp(net2(i,j));
end
end
for j=1:7
m1(j)=f2(1,j);
m2(j)=f2(2,j);
end
for i=1:7
for j=1:7
ff3(i,j)=m2(i)*m1(j);
end
end
f3=[ff3(1,:),ff3(2,:),ff3(3,:),ff3(4,:),ff3(5,:),ff3(6,:),ff3(7,:)];
f4=w_1'*f3';
ym(n)=f4;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sum_e=sum_e+e(n)*ts;
kup(n)=kp*e(n)+ki*sum_e+kd*(e(n)-e_1)/ts;
ku(n)=kup(n)+ym(n);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
e(n)=h3(n)-ym(n);
d_w=0*w_1;
for j=1:49
d_w(j)=xite*e(n)*f3(j);
end
w=w_1+d_w+alfa*(w_1-w_2);
delta2=-e(n)*w'*f3';
d_b=0*b_1;
for j=1:7
d_b(j)=xite*delta2*2*((x(1)-c(1,j)^2)*b(j)^-3);
end
b=b_1+d_b+alfa*(b_1-b_2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d_c=0*c_1;
for i=1:2
for j=1:7
d_c(i,j)=-xite*delta2*2*(x(i)-c(i,j))*b(j)^-2;
end
end
c=c_1+d_c+alfa*(c_1-c_2);
u_1=ku(n);
y_1=h3(n);
w_2=w_1;
w_1=w;
c_2=c_1;
c_1=c;
b_2=b_1;
b_1=b;
end
figure(1);
plot(time,h3,'r',time,r,'b');
xlabel('time(s)');ylabel('Approaching');
figure(2);
plot(time,h3-r,'r');
xlabel('time(s)');ylabel('Approaching error');
这是MATLAB的m程序吗?
是啊 运行出来错误的图图。