用S函数编的一个Buck-book电路,大家帮我看看对不
我在仿真的时候,没有输出结果代码
function = han_dcdc(t,x,u,flag)switchflag,
%%%%%%%%%%
% 初始化 %
%%%%%%%%%%
case 0,
=mdlInitializeSizes;
%%%%%%%%%%%%%%%
% 离散状态更新 %
%%%%%%%%%%%%%%%
case 1,
sys=mdlDerivatives(t,x,u);
%%%%%%%%%%%%%
% 输出量计算 %
%%%%%%%%%%%&&
case 3,
sys=mdlOutputs(x);
%%%%%%%%%%
% 未使用 %
%%%%%%%%%%
case {2,4,9},
sys=[];
%%%%%%%%%%%%
% 处理错误 %
%%%%%%%%%%%%
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
% end sfuntmpl
%
%=============================================================================
% mdlInitializeSizes
% 整个系统初始化
%=============================================================================
%
function =mdlInitializeSizes(t,x,u);
%
% 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= 0;
sizes.NumDiscStates= 2;
sizes.NumOutputs = 2;
sizes.NumInputs = 1;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed
sys = simsizes(sizes);
%
% initialize the initial conditions
%
x0= ;
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts= ;
% end mdlInitializeSizes
%
%=============================================================================
% mdlUpdate
% 更新离散系统状态变量
%=============================================================================
%
function sys=mdlDerivatives(t,x,u);
if u==1
sys(1,1) = 10/2.7e-3;
sys(2,1) = -1*x(2)/(10*270e-6);
else if u==0
sys(1,1) = -1*x(2)/2.7e-3;
sys(2,1) = 1*x(1)/270e-6-1*x(2)/(10*270e-6);
else if0 < u <1
sys(1,1) = -1*x(2)/2.7e-3+u*(1*x(2)/2.7e-3+10/2.7e-3);
sys(2,1) = -1*x(1)/270e-6-1*x(2)/(10*270e-6)-u*1*x(1)/270e-6;
end
end
end
% end mdlUpdate
%
%=============================================================================
% mdlOutputs
% 计算系统输出变量:返回两个状态
%=============================================================================
%
function sys=mdlOutputs(x)
sys = x; 你用的是连续量 2个 就是把sizes.NumContStates= 0;
sizes.NumDiscStates= 2;
后面的0和2 对调下
页:
[1]