声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1724|回复: 3

[控制系统类] 用S函数编的一个Buck-book电路,大家帮我看看对不

[复制链接]
发表于 2010-3-24 10:17 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
我在仿真的时候,没有输出结果
仿真电路.JPG
回复
分享到:

使用道具 举报

 楼主| 发表于 2010-3-24 10:18 | 显示全部楼层

代码

function [sys,x0,str,ts] = han_dcdc(t,x,u,flag)
switch  flag,
  %%%%%%%%%%
  % 初始化 %
  %%%%%%%%%%
   case 0,
  [sys,x0,str,ts]=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 [sys,x0,str,ts]=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  = [0;0];
%
% str is always an empty matrix
%
str = [];
%
% initialize the array of sample times
%
ts  = [0 0];
% 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 if  0 < 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;
发表于 2010-3-25 09:20 | 显示全部楼层
你用的是连续量 2个
 楼主| 发表于 2010-3-25 21:56 | 显示全部楼层
就是把sizes.NumContStates  = 0;
sizes.NumDiscStates  = 2;
后面的0和2 对调下
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-23 18:12 , Processed in 0.088681 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表