# 5 麦片

050

2主题 0最佳答案

 function [sys,x0,str,ts] = obser(t,x,u,flag) switch flag, case 0,     [sys,x0,str,ts]=mdlInitializeSizes; case 1,     sys=mdlDerivatives(t,x,u); case 3,     sys=mdlOutputs(t,x,u); case {1,2,4,9}     sys=[]; otherwise     error(['Unhandled flag = ',num2str(flag)]); end function [sys,x0,str,ts]=mdlInitializeSizes global c b sizes = simsizes; sizes.NumContStates  = 33; sizes.NumDiscStates  = 0; sizes.NumOutputs     = 2; sizes.NumInputs      = 5; sizes.DirFeedthrough = 1; sizes.NumSampleTimes = 0; sys = simsizes(sizes); x0=zeros(1,33); str=[]; ts=[]; c1=0.00001*[-25 -20 -15 -10 -5 0 5 10 15 20 25]; c2=1000*[-25 -20 -15 -10 -5 0 5 10 15 20 25]; c=[c1;c2]; b=10; function sys=mdlDerivatives(t,x,u) global c b y=u(1); ut=u(2); x1p=u(3); x2p=u(4); x3p=u(5); xp=[x1p x2p x3p]'; yp=x1p; ye=y-yp; h=zeros(11,1); for j=1:1:11     h(j)=exp(-norm(xp-c(:,j))^2/(2*b^2)); end h_bar=x(23:1:33); F1=0.05*eye(11); F2=500*eye(11); k1=0.01;k2=100; W1=[x(1) x(2) x(3) x(4) x(5) x(6) x(7) x(8) x(9) x(10) x(11)]; W2=[x(12) x(13) x(14) x(15) x(16) x(17) x(18) x(19) x(20) x(21) x(22)]; dW1=F1*h_bar*ye-k1*F1*abs(ye)*W1'; dW2=F2*h_bar*ye*ut-k2*F2*abs(ye)*W2'; for i=1:1:11     sys(i)=dW1(i);     sys(i+11)=dW2(i); end for i=23:1:33     sys(i)=h(i-22)-0.5*x(i); end function sys=mdlOutputs(t,x,u) global c b W1=[x(1) x(2) x(3) x(4) x(5) x(6) x(7) x(8) x(9) x(10) x(11)]; W2=[x(12) x(13) x(14) x(15) x(16) x(17) x(18) x(19) x(20) x(21) x(22)]; h_bar=x(23:1:33); fxp=W1*h_bar; gxp=W2*h_bar; sys(1)=fxp; sys(2)=gxp; 求各位大神帮忙指点一下，运行之后总是说这段程序中矩阵维度不一样，这是怎么回事？

# 61 麦片

50500

7主题 0最佳答案