发电机代码以及代码教程附带仿真结果图.docx
《发电机代码以及代码教程附带仿真结果图.docx》由会员分享,可在线阅读,更多相关《发电机代码以及代码教程附带仿真结果图.docx(25页珍藏版)》请在冰豆网上搜索。
发电机代码以及代码教程附带仿真结果图
%%FuzzyTunningPIDControl
%clearall;
%closeall;
%a=newfis('fuzzypid');
%
%a=addvar(a,'input','e',[-3,3]);
%a=addmf(a,'input',1,'NB','zmf',[-3,-1]);
%a=addmf(a,'input',1,'NM','trimf',[-3,-2,0]);
%a=addmf(a,'input',1,'NS','trimf',[-3,-1,1]);
%a=addmf(a,'input',1,'Z','trimf',[-2,0,2]);
%a=addmf(a,'input',1,'PS','trimf',[-1,1,3]);
%a=addmf(a,'input',1,'PM','trimf',[0,2,3]);
%a=addmf(a,'input',1,'PB','smf',[1,3]);
%
%a=addvar(a,'input','ec',[-3,3]);
%a=addmf(a,'input',2,'NB','zmf',[-3,-1]);
%a=addmf(a,'input',2,'NM','trimf',[-3,-2,0]);
%a=addmf(a,'input',2,'NS','trimf',[-3,-1,1]);
%a=addmf(a,'input',2,'Z','trimf',[-2,0,2]);
%a=addmf(a,'input',2,'PS','trimf',[-1,1,3]);
%a=addmf(a,'input',2,'PM','trimf',[0,2,3]);
%a=addmf(a,'input',2,'PB','smf',[1,3]);
%
%a=addvar(a,'output','kp',[-0.3,0.3]);
%a=addmf(a,'output',1,'NB','zmf',[-0.3,-0.1]);
%a=addmf(a,'output',1,'NM','trimf',[-0.3,-0.2,0]);
%a=addmf(a,'output',1,'NS','trimf',[-0.3,-0.1,0.1]);
%a=addmf(a,'output',1,'Z','trimf',[-0.2,0,0.2]);
%a=addmf(a,'output',1,'PS','trimf',[-0.1,0.1,0.3]);
%a=addmf(a,'output',1,'PM','trimf',[0,0.2,0.3]);
%a=addmf(a,'output',1,'PB','smf',[0.1,0.3]);
%
%a=addvar(a,'output','ki',[-0.06,0.06]);
%a=addmf(a,'output',2,'NB','zmf',[-0.06,-0.02]);
%a=addmf(a,'output',2,'NM','trimf',[-0.06,-0.04,0]);
%a=addmf(a,'output',2,'NS','trimf',[-0.06,-0.02,0.02]);
%a=addmf(a,'output',2,'Z','trimf',[-0.04,0,0.04]);
%a=addmf(a,'output',2,'PS','trimf',[-0.02,0.02,0.06]);
%a=addmf(a,'output',2,'PM','trimf',[0,0.04,0.06]);
%a=addmf(a,'output',2,'PB','smf',[0.02,0.06]);
%
%a=addvar(a,'output','kd',[-3,3]);
%a=addmf(a,'output',3,'NB','zmf',[-3,-1]);
%a=addmf(a,'output',3,'NM','trimf',[-3,-2,0]);
%a=addmf(a,'output',3,'NS','trimf',[-3,-1,1]);
%a=addmf(a,'output',3,'Z','trimf',[-2,0,2]);
%a=addmf(a,'output',3,'PS','trimf',[-1,1,3]);
%a=addmf(a,'output',3,'PM','trimf',[0,2,3]);
%a=addmf(a,'output',3,'PB','smf',[1,3]);
%
%rulelist=[1171511;
%1271311;
%1362111;
%1462111;
%1553111;
%1644211;
%1744511;
%
%2171511;
%2271311;
%2362111;
%2453211;
%2553211;
%2644311;
%2734411;
%
%3161411;
%3262311;
%3363211;
%3453211;
%3544311;
%3635311;
%3735411;
%
%4162411;
%4262311;
%4353311;
%4444311;
%4535311;
%4626311;
%4726411;
%
%5152411;
%5253411;
%5344411;
%5435411;
%5535411;
%5626411;
%5727411;
%
%6154711;
%6244511;
%6335511;
%6425511;
%6526511;
%6627511;
%6717711;
%
%7144711;
%7244611;
%7325611;
%7426611;
%7526511;
%7617511;
%7717711];
%
%a=addrule(a,rulelist);
%a=setfis(a,'DefuzzMethod','mom');
%writefis(a,'fuzzypid');
%
%a=readfis('fuzzypid');
%
%%PIDcontroller
%ts=0.001;
%sys=tf(5.235e005,[1,87.35,1.047e004,0],'inputdelay',240);
%dsys=c2d(sys,ts,'tustin');
%[num,den]=tfdata(dsys,'v');
%
%u_1=0.0;u_2=0.0;u_3=0.0;
%%
%y_1=0;y_2=0;y_3=0;
%
%x=[0,0,0];
%
%error_1=0;
%e_1=0.0;
%ec_1=0.0;
%
%kp0=0.40;
%kd0=1.0;
%ki0=0.0;
%fork=1:
1:
500
%time(k)=k*ts;
%
%rin(k)=1;
%%UsingfuzzyinferencetotunningPID
%k_pid=evalfis([e_1,ec_1],a);
%kp(k)=kp0+k_pid
(1);
%ki(k)=ki0+k_pid
(2);
%kd(k)=kd0+k_pid(3);
%u(k)=kp(k)*x
(1)+kd(k)*x
(2)+ki(k)*x(3);
%
%ifk==300%addingdisturbance(1.0vattime0.3s)
%u(k)=u(k)+1.0;
%end
%ifu(k)>=10
%u(k)=10;
%end
%ifu(k)<=-10
%u(k)=-10;
%end
%
%yout(k)=-den
(2)*y_1-den(3)*y_2-den(4)*y_3+num
(1)*u(k)+num
(2)*u_1+num(3)*u_2+num(4)*u_3;
%error(k)=rin(k)-yout(k);
%
%%%%%%%%%%%%%%%ReturnofPIDparameters%%%%%%%%%%%%%%%%%%
%u_3=u_2;
%u_2=u_1;
%u_1=u(k);
%
%y_3=y_2;
%y_2=y_1;
%y_1=yout(k);
%
%x
(1)=error(k);%CaclulatingP
%x
(2)=error(k)-error_1;%CalculatingD
%x(3)=x(3)+error(k);%CalculatiingI
%
%e_1=x
(1);
%ec_1=x
(2);
%
%error_2=error_1;
%error_1=error(k);
%end
%showrule(a)
%figure(9);plot(time,rin,'b',time,yout,'r');
%xlabel('time(s)');ylabel('rin,yout');
%
%figure(10);plot(time,error,'r');
%xlabel('time(s)');ylabel('error');
%{
%%figure(3);plot(time,u,'r');
%%xlabel('time(s)');ylabel('u');
%figure(4);plot(time,kp,'r');
%xlabel('time(s)');ylabel('kp');
%figure(5);plot(time,ki,'r');
%xlabel('time(s)');ylabel('ki');
%figure(6);plot(time,kd,'r');
%xlabel('time(s)');ylabel('kd');
%figure(7);plotmf(a,'input',1);
%figure(8);plotmf(a,'input',2);
%figure(9);plotmf(a,'output',1);
%figure(10);plotmf(a,'output',2);
%figure(11);plotmf(a,'output',3);
%plotfis(a);
%}
%fuzzyfuzzypid.fis
%
%R=[0.81,0,0,0,0,0;0,0.81,0,0,0,0;0,0,0.81,0,0,0;0,0,0,0.81,0,0;0,0,0,0,0.00157,0;0,0,0,0,0,0.00157];
%G=[0,0.24,0,0,0,0.00267;-0.24,0,0,0,-0.00267,0;0,0,0,0.63,0,0.0043;0,0,-0.63,0,0.0043,0;0,0,0,0,0,0;0,0,0,0,0,0];
%L1=[177.62,0,-101.31,0,-14842,0;0,177.62,0,101.31,0,-14842;-101.31,0,63.74,0,9106.1,0;0,101.31,0,63.74,0,-9106.1;-14842,0,9106.1,0,1.3341e+006,0;0,-14842,0,-9106.1,0,1.3341e+006];
%X=[0;0;0;0;0;0];
%X1=[0;0;0;0;0;0];
%U=[380;0;0;0;0;0];
%H=0.0001;%步长
%
%
%Tem=0;
%ala=0;
%sun=0;
%TE=0;
%k=0;
%v=8;
%c=0;%presentbeidangle
%wr0=0;
%
%ang0=0.1;
%beid0=0;
%c=0;
%kls=1000;Bls=100;Jr=1;Jg=1;ng=4.488;Tb=0.2;
%wg0=wr0*ng;
%a11=-(Bls)/Jr;
%a12=Bls/(Jr*ng);
%a14=-kls/Jr;
%b1=1/Jr;
%a21=Bls/(ng*Jg);
%a22=-Bls/(ng*ng*Jg);
%a24=kls/(ng*Jg);
%b2=1/(Jg);
%a33=-1/Tb;
%b3=1/Tb;
%a41=1;
%a42=-1;
%R0=4;
%Ta=0;
%Tem=0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%fc=10
%fori=0:
H:
40
%
%if(i>20),c=2,end
%if(i>40),fc=-5,end
%if(i>40),fc=-10,end
%k=k+1;
%
%wr=H*(a11*wr0+a12*wg0+a14*ang0+b1*Ta)+wr0;
%
%wg=H*(a21*wr0+a22*wg0+a24*ang0+b2*Tem)+wg0;
%beid=H*(a33*beid0+b3*c)+beid0;
%ang=(wr0-wg0/ng)*H+ang0;
%
%sun=sun+(wg+wg0)/2*H;
%%SH=314*i-3*sun;
%U(1,1)=380*cos(314*i-3*sun);
%U(2,1)=-380*sin(314*i-3*sun);
%%U(3,1)=7*cos(sun+2*pi*fc*i+pi/3);
%%U(4,1)=7*sin(sun+2*pi*fc*i+pi/3);thisisthedirectcase
%%U(3,1)=0*cos(sun+2*pi*fc*i+pi/3);%thisistheshortcircuitcase
%%U(4,1)=0*sin(sun+2*pi*fc*i+pi/3);abovecasefunction
%%if(fc>0andfc<5)
%%U(3,1)=(7+20*abs(fc))*cos(sun+2*pi*fc*i+pi/3);
%%U(4,1)=(7+20*abs(fc))*sin(sun+2*pi*fc*i+pi/3);
%%end
%if(abs(fc)>=5)
%
%%U(3,1)=450*cos(sun+2*pi*fc*i+pi/3);
%%U(4,1)=450*sin(sun+2*pi*fc*i+pi/3);
%%if(i<=20)
%U(3,1)=35*abs(fc)*cos(sun+2*pi*fc*i+pi/3);
%U(4,1)=35*abs(fc)*sin(sun+2*pi*fc*i+pi/3);
%%else
%%%U(3,1)=345*cos(sun+2*pi*fc*i+pi/3);
%%U(4,1)=345*sin(sun+2*pi*fc*i+pi/3);
%%end
%elseif(fc<0)
%U(3,1)=(7+14*abs(fc))*cos(sun+2*pi*fc*i+pi/3);
%U(4,1)=(7+14*abs(fc))*sin(sun+2*pi*fc*i+pi/3);
%else
%U(3,1)=(7+20*abs(fc))*cos(sun+2*pi*fc*i+pi/3);
%U(4,1)=(7+20*abs(fc))*sin(sun+2*pi*fc*i+pi/3);
%end
%
%X1=L1*(U-wg*G*X-R*X);
%X=X+H*X1;
%Tem=3*0.00089*(X(1,1)*X(6,1)-X(2,1)*X(5,1))+0.0043*(X(3,1)*X(6,1)+X(4,1)*X(5,1));
%Tls(k)=kls*ang+Bls*(wr-wg/ng);
%s1(k)=X(1,1);
%
%
%s3(k)=X(3,1);
%
%
%s6(k)=X(6,1);
%M=wr*30/3.14;
%N=wg*30/3.14;
%
%
%b(k)=N;
%d(k)=M;
%a(k)=i;
%
%
%
%lam=wr*R0/v;
%lam1=1/(1/(lam-0.02*c)-0.003/(1+c^3));
%m=0.73*(151/lam1-0.58*c-0.002*c^2.14-13.2)*exp(-18.4/lam1);
%if(m<0)
%cp(k)=0;
%else
%cp(k)=m;
%end
%cpp=cp(k);
%Ta=cpp*0.5*1.25*3.14*R0*R0*v^3/wr;
%T(k)=Ta;
%Pmec(k)=Ta*wr;
%Pp(k)=3*1.5*(U(1,1)*X(1,1)+U(2,1)*X(2,1));
%Pc(k)=1.5*(U(3,1)*X(3,1)+U(4,1)*X(4,1));
%P1(k)=Tem*wg;
%Q(k)=3*1.5*(U(1,1)*X(2,1)-U(2,1)*X(1,1));
%an(k)=ang;
%
%%Q(k)=
%
%wr0=wr;
%wg0=wg;
%beid0=beid;
%ang0=ang;
%
%
%end
%i=0:
0.0001:
3
%
%plot(a,b,'r')
%holdon
%figure
(1)
%x=[00.20.40.60.81.01.21.41.61.82.02.22.42.62.83.03.23.43.84.04.24.44.64.85.068102040];
%y=[080140190235280334382430492552570586594600600600600600600600600600600600600600600600600];
%holdon;
%xx=linspace(0,7.2);
%yy=spline(x,y,xx);
%
%holdon
%plot(xx,yy,'r')
%axis([040,0700]);
%a=[5,40];b=[600,600];
%plot(a,b,'r')
%xlabel('时间/s');
%ylabel('转速/r');
%
%x1=[00.20.40.60.81.01.21.41.61.82.02.22.42.62.83.03.23.43.84.04.24.44.64.85.068102040];
%y1=[070120160215270314352420452512550586640569604631589624596610600600600600600600600600600];
%xx1=linspace(0,7.2);
%yy1=spline(x1,y1,xx1);
%
%holdon
%plot(xx1,yy1)
%axis([040,0700]);
%a1=[5,40];b1=[600,600];
%plot(a1,b1)
%xlabel('时间/s');
%ylabel('转速/r');
%a=[5,40];b=[600,600];
%plot(a,b,'r')
%holdon
%x2=[00.20.40.60.81.01.21.41.61.82.02.22.42.62.83.03.23.43.84.04.24.44.64.85.0];
%y2=[00.650.720.840.921.01.131.241.281.301.121.00.920.881.021.161.030.961.010.991.01.01.01.01.0];
%xx2=linspace(0,5.2);
%yy2=spline(x2,y2,xx2);
%figure
(2)
%holdon
%plot(xx2,yy2)
%axis([040,02]);
%a2=[5,40];b2=[1.0,1.0];
%plot(a2,b2)
%xlabel('时间/s');
%ylabel('端电压/v');
%
%x2=[00.20.40.60.81.01.21.41.61.82.02.22.42.62.83.03.23.43.84.04.24.44.64.85.0];
%y2=[00.600.840.880.961.081.020.901.040.961.01.020.981.010.991.01.01.01.01.01.01.01.01.01.0];
%xx2=linspace(0,5.2);
%yy2=spline(x2,y2,xx2);
%
%holdon
%plot(xx2,yy2,'r')
%axis([040,02]);
%a2=[5,40];b2=[1.0,1.0];
%plot(a2,b2,'r')
%xlabel('时间/s');
%ylabel('端电压/v');
%
%
%figure(3)
%holdon
%xt1=[00.20.4