For a model
with Nx states, Ny outputs, and Nu inputs:
a is an Nx-by-Nx real- or complex-valued matrix.
b is an Nx-by-Nu real- or complex-valued matrix.
c is an Ny-by-Nx real- or complex-valued matrix.
d is an Ny-by-Nu real- or complex-valued matrix.
To set D = 0 , set d to the scalar 0 (zero), regardless of the
dimension.
离散模型:
sys = ss(a,b,c,d,Ts) creates the discrete-time model
with sample time Ts (in seconds). Set Ts = -1 or Ts = [] to leave
the sample time unspecified.
1.3MATLAB tf2ss函数命令:
将传递函数模型转化为状态空间模型,单输入单输出系统转换如下:
利用该命令不仅可以转换SISO系统也可以转换MIMO系统,如下MISO系统也可以:
den= [0 2
3; 1 2 1];
num= [1 0.4 1];
[A,B,C,D] = tf2ss(den,num)
结果:
A =
-0.4000
-1.0000
1.0000
0
B =
1
0
C =
2.0000
3.0000
1.6000
0
D =
0
1
2、实例仿真
2.1假设工业过程某传递函数:
den= [1.5];
num= [1 5 1];
[A,B,C,D] = tf2ss(den,num)
结果:
a
=
x1
x2
x1
-5 -1
x2
1
0
b =
u1
x1
1
x2
0
c =
x1
x2
y1
0
1.5
d =
u1
y1
0
所以有:
2.2修改S-Function模板参数:
从结果可以看出,系统有两个状态,没有离散状态,输入1个,输出1个,无直通反馈,一种采用时间,打开模板,复制代码。
function[sys,x0,str,ts,simStateCompliance]
= sfuntmpl(t,x,u,flag)【一个主函数,需修改原函数名:sfuntmpl】
%SFUNTMPL General MATLAB S-Function Template
% With MATLAB S-functions, you
can define you own ordinary differential
% equations (ODEs), discrete
system equations, and/or just about
% any type of algorithm to be
used within a Simulink block diagram.
%
% The general form of an MATLAB
S-function syntax is:
%
[SYS,X0,STR,TS,SIMSTATECOMPLIANCE]
= SFUNC(T,X,U,FLAG,P1,...,Pn)
%
% What is returned by SFUNC at
a given point in time, T, depends on the
% value of the FLAG, the
current state vector, X, and the current
% input vector, U.
%
% FLAG
RESULT
DESCRIPTION
% -----
------
--------------------------------------------
% 0
[SIZES,X0,STR,TS]
Initialization, return system sizes in
SYS,
%
initial
state in X0, state ordering strings
%
in
STR, and sample times in TS.
% 1
DX