概述
系统是用S-Function 写的,请见附件,为了使用linmod函数,故建立xls文件,包含S-Function模块,
和一个阶跃。模型是2输入2输出,linmod 之后,得到a 矩阵,但是b、c、d 矩阵显示是空集。感觉不合理。
请大神指导帮忙。
另外,对于这个系统,怎么用 trim解稳态点。谢谢各位。
matlab版本R2012b,系统64位window7.
S-Function中的代码:
function [sys,x0,str,ts,simStateCompliance] = model0402(t,x,u,flag)
switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes;
%%%%%%%%%%%%%%%
% Derivatives %
%%%%%%%%%%%%%%%
case 1,
sys=mdlDerivatives(t,x,u);
%%%%%%%%%%
% Update %
%%%%%%%%%%
case 2,
sys=mdlUpdate(t,x,u);
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
case 3,
sys=mdlOutputs(t,x,u);
%%%%%%%%%%%%%%%%%%%%%%%
% GetTimeOfNextVarHit %
%%%%%%%%%%%%%%%%%%%%%%%
case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);
%%%%%%%%%%%%%
% Terminate %
%%%%%%%%%%%%%
case 9,
sys=mdlTerminate(t,x,u);
%%%%%%%%%%%%%%%%%%%%
% Unexpected flags %
%%%%%%%%%%%%%%%%%%%%
otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));
end
% end sfuntmpl
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes
global CAs
global Ts
%
% call simsizes for a sizes structure, fill it in and convert it to a
% sizes array.
%
% Note that in this example, the values are hard coded. This is not a
% recommended practice as the characteristics of the block are typically
% defined by the S-function parameters.
%
sizes = simsizes;
sizes.NumContStates = 2;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 2;
sizes.NumInputs = 2;
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
x0 = [2; 400];
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts = [0 0];
% Specify the block simStateCompliance. The allowed values are:
% 'UnknownSimState', < The default setting; warn and assume DefaultSimState
% 'DefaultSimState', < Same sim state as a built-in block
% 'HasNoSimState', < No sim state
% 'DisallowSimState' < Error out when saving or restoring the model sim state
simStateCompliance = 'UnknownSimState';
% end mdlInitializeSizes
%
%=============================================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=============================================================================
%
function sys=mdlDerivatives(t,x,u)
global CAs
global Ts
T0 = 300;
F = 5;
V = 1;
k0 = 8.46*10^6;
Cp = 0.231;
pro = 1000;
E = 5*10^4;
dH = -1.15*10^4;
R = 8.314;
CAs = 2;
Ts = 400;
n=2
sys = [F/V*(u(1)-x(1))-k0*exp(-E/(R*x(2)))*x(1)^n;...
F/V*(T0-x(2)) - dH/(pro*Cp)*k0*exp(-E/(R*x(2)))*x(1)^n + (u(2))/(V*pro*Cp)];
% end mdlDerivatives
%
%=============================================================================
% mdlUpdate
% Handle discrete state updates, sample time hits, and major time step
% requirements.
%=============================================================================
%
function sys=mdlUpdate(t,x,u)
global CAf
sys = [];
% end mdlUpdate
%
%=============================================================================
% mdlOutputs
% Return the block outputs.
%=============================================================================
%
function sys=mdlOutputs(t,x,u)
%%untitled中专门求解平衡点的 中间那一段,可以作图,平衡点有三个,应该选【2 400】
global CAs
global Ts
sys = [x(1);x(2)]; %% DMC的输入输出都必须减去平衡点的值
% end mdlOutputs
%
%=============================================================================
% mdlGetTimeOfNextVarHit
% Return the time of the next hit for this block. Note that the result is
% absolute time. Note that this function is only used when you specify a
% variable discrete-time sample time [-2 0] in the sample time array in
% mdlInitializeSizes.
%=============================================================================
%
function sys=mdlGetTimeOfNextVarHit(t,x,u)
global CAs
global Ts
sampleTime = 1; % 文献中 0.01hr = 36 sec 化成 秒单位 Example, set the next hit to be one second later.
sys = t + sampleTime;
% end mdlGetTimeOfNextVarHit
%
%=============================================================================
% mdlTerminate
% Perform any end of simulation tasks.
%=============================================================================
%
function sys=mdlTerminate(t,x,u)
global CAs
global Ts
sys = [];
% end mdlTerminate
model.png
(28.2 KB, 下载次数: 3)
2015-4-6 20:51 上传
2015-4-6 20:52 上传
点击文件名下载附件
4.63 KB, 下载次数: 32
S-Function
最后
以上就是喜悦发夹为你收集整理的matlab linmod,linmod 线性化系统的全部内容,希望文章能够帮你解决matlab linmod,linmod 线性化系统所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复