unction [sys,x0,str,ts] = spacemodel(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
sizes = simsizes;
sizes.NumContStates = 2;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 1;
sizes.NumInputs = 5;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 0;
sys = simsizes(sizes);
x0 = [0 0];
str = [];
ts = [];
function sys=mdlDerivatives(t,x,u)
str = [];
k=0.50;
k1=10;
e=u(1);de=u(2);
s=k*e;
ds=k*u(2);
s1=s;ds1=ds;
FS1=0;
u1(1)=exp(-0.5*[s1+pi/6]^2);
u1(2)=exp(-0.5*[s1+pi/12]^2);
u1(3)=exp(-0.5*[s1+pi/24]^2);
u1(4)=exp(-0.5*[s1]^2);
u1(5)=exp(-0.5*[s1-pi/24]^2);
u1(6)=exp(-0.5*[s1-pi/12]^2);
u1(7)=exp(-0.5*[s1-pi/6]^2);
u2(1)=exp(-0.5*[ds1+pi/6]^2);
u2(2)=exp(-0.5*[ds1+pi/12]^2);
u2(3)=exp(-0.5*[ds1+pi/24]^2);
u2(4)=exp(-0.5*[ds1]^2);
u2(5)=exp(-0.5*[ds1-pi/24]^2);
u2(6)=exp(-0.5*[ds1-pi/12]^2);
u2(7)=exp(-0.5*[ds1-pi/6]^2);
y=[-1,-1,-1,-1,-0.4,0,0;
-1,-1,-1,-1,-0.4,0,0;
-0.4,-0.4,-0.4,-0.4,0,0.1,0.1;
-0.4,-0.4,-0.1,0,0.1,0.4,0.4;
-0.1,-0.1,0,0.4,0.4,0.4,0.4;
0,0,0.4,1,1,1,1;
0,0,0.4,1,1,1,1];
for l1=1:1:7
for l2=1:1:7
FS1=FS1+u1(l1)*u2(l2)*y(l1,l2);
end
end
S1=20*k1*s*FS1;
S2=0.02*k1*abs(s);
sys(1)=S1;
sys(2)=S2;
function sys=mdlOutputs(t,x,u)
sys=ud; |