声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1438|回复: 4

[电力电机类] 帮忙看看s函数的错误

[复制链接]
发表于 2007-6-20 11:46 | 显示全部楼层 |阅读模式

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

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

x
请高手帮忙看看这个s函数的错误是什么意思?
该如何改呢?
谢谢拉
cuowu.JPG
回复
分享到:

使用道具 举报

 楼主| 发表于 2007-6-20 11:46 | 显示全部楼层
s函数如下:

function [sys,x0,str,ts] = BDFM(t,x,u,flag)
%SIMOM Example state-space M-file S-function with internal A,B,C,D matrices
%   This S-function implements a system described by state-space equations:
%   
%           dx/dt = A*x + B*u
%               y = C*x + D*u
%   
%   where x is the state vector, u is vector of inputs, and y is the vector
%   of outputs. The matrices, A,B,C,D are embedded into the M-file.
%   
%   See sfuntmpl.m for a general S-function template.
%
%   See also SFUNTMPL.
   
%电机的数学模型为
%  [iqp' idp' icp' idc' iqr' idr']'=-inv(L)*[R+G]*[iqp idp icp idc iqr idr]'+inv(L)*[uqp udp uqc udc uqr  udr]';
%   uqr=0,  udr=0
%  R=[Rp 0 0 0 0 0;
%     0 Rp 0 0 0 0;
%     0 0 Rc 0 0 0;
%     0 0 0 Rc 0 0;
%     0 0 0 0 Rr 0;
%     0 0 0 0 0 Rr]
%  G=[        0       Pp*Lsp*w    0       0        0     Pp*Mp*w;
%        -Pp*Lsp*w        0       0       0    -Pp*Mp*w     0     ;
%             0           0       0   Pc*Lsc*w     0     Pc*Mc*w  ;
%             0           0   -Pc*Lsc*w   0     Pc*Mc*w     0]    ;
%             0           0       0       0        0        0     ;
%             0           0       0       0        0        0       ]
%  L=[ Lsp   0    0    0     Mp   0 ;
%       0   Lsp   0    0     0    Mp;
%       0    0   Lsc   0    -Mc   0 ;
%       0    0    0   Lsc    0    Mc;
%       Mp   0   -Mc   0     Lr   0 ;
%       0    Mp   0    Mc    0    Lr  ]
Rp=0.81;
Rc=0.81;
Lsp=80e-3;
Lsc=630e-3;
Mp=0.89e-3;
Mc=4.3e-3;
Pp=3;
Pc=1;
Lr=0.04e-3;
Rr=1.57e-3;



switch flag,

  %%%%%%%%%%%%%%%%%%
  % Initialization %
  %%%%%%%%%%%%%%%%%%
  case 0     
    [sys,x0,str,ts] = mdlInitializeSizes;                                

  %%%%%%%%%%%%%%%
  % Derivatives %
  %%%%%%%%%%%%%%%
  case 1,
    sys = mdlDerivatives(t,x,u);

  %%%%%%%%%%%
  % Outputs %
  %%%%%%%%%%%
  case 3,
    sys = mdlOutputs(t,x,u);

  %%%%%%%%%%%%%
  % Terminate %
  %%%%%%%%%%%%%
case{2,4,9}
sys=[]; % Unused flags
otherwise
error(['Unhandled flag=',num2str(flag)]); % Error handling
end
%end simom

%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts] = mdlInitializeSizes

sizes = simsizes;

sizes.NumContStates  = 7;  % 有iqp, idp, icp ,idc ,iqr, idr,w
sizes.NumDiscStates  = 0;
sizes.NumOutputs     = 4;  %输出有Te,w,iqp ,idp
sizes.NumInputs      = 5;  % 输入有uqp ,udp, uqc, udc ,TL
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;

sys = simsizes(sizes);
x0  = zero(7,1);
str = [ ];
ts  = [0 0];

% end mdlInitializeSizes
%
%=============================================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=============================================================================
%
function sys = mdlDerivatives(t,x,u)
J=0.038;
w=x(7);
  R=[Rp 0 0 0 0 0;
    0 Rp 0 0 0 0;
    0 0 Rc 0 0 0;
    0 0 0 Rc 0 0;
    0 0 0 0 Rr 0;
    0 0 0 0 0 Rr];
  G=[ 0 Pp*Lsp*w 0 0 0 Pp*Mp*w;
      -Pp*Lsp*w 0 0 0 -Pp*Mp*w 0;
      0 0 0 Pc*Lsc* 0 Pc*Mc*w;
      0 0 -Pc*Lsc*w 0 Pc*Mc*w 0;
      0 0 0 0 0 0;
      0 0 0 0 0 0]
  L=[ Lsp   0    0    0     Mp   0 ;
       0   Lsp   0    0     0    Mp;
       0    0   Lsc   0    -Mc   0 ;
       0    0    0   Lsc    0    Mc;
       Mp   0   -Mc   0     Lr   0 ;
       0    Mp   0    Mc    0    Lr  ];
   u=[u(1);u(2);u(3);u(4);0;0]
   sys(1:6)=-inv(L)*(R+G)*x(1:6)+-inv(L)*u;
   Te=Pp*Mp*[x(1)*x(6)-x(2)*x(5)]+Pc*Mc*[x(3)*x(6)+x(4)*x(5)];
   
   sys(7)=(Te-u(5))/J;


% end mdlDerivatives
%
%=============================================================================
% mdlOutputs
% Return the output vector for the S-function
%=============================================================================
%
function sys = mdlOutputs(t,x,u)
sys(1)=Pp*Mp*[x(1)*x(6)-x(2)*x(5)]+Pc*Mc*[x(3)*x(6)+x(4)*x(5)];
sys(2)=x(7);
sys(3:4)=x(1:2);

% end mdlOutputs
发表于 2007-6-21 22:01 | 显示全部楼层
这次再试一下,侃侃还有没有错,错在那里自己对比着找:lol :lol
function [sys,x0,str,ts] = BDFM(t,x,u,flag)
%SIMOM Example state-space M-file S-function with internal A,B,C,D matrices
%   This S-function implements a system described by state-space equations:
%   
%           dx/dt = A*x + B*u
%               y = C*x + D*u
%   
%   where x is the state vector, u is vector of inputs, and y is the vector
%   of outputs. The matrices, A,B,C,D are embedded into the M-file.
%   
%   See sfuntmpl.m for a general S-function template.
%
%   See also SFUNTMPL.
   
%电机的数学模型为
%  [iqp' idp' icp' idc' iqr' idr']'=-inv(L)*[R+G]*[iqp idp icp idc iqr idr]'+inv(L)*[uqp udp uqc udc uqr  udr]';
%   uqr=0,  udr=0
%  R=[Rp 0 0 0 0 0;
%     0 Rp 0 0 0 0;
%     0 0 Rc 0 0 0;
%     0 0 0 Rc 0 0;
%     0 0 0 0 Rr 0;
%     0 0 0 0 0 Rr]
%  G=[        0       Pp*Lsp*w    0       0        0     Pp*Mp*w;
%        -Pp*Lsp*w        0       0       0    -Pp*Mp*w     0     ;
%             0           0       0   Pc*Lsc*w     0     Pc*Mc*w  ;
%             0           0   -Pc*Lsc*w   0     Pc*Mc*w     0]    ;
%             0           0       0       0        0        0     ;
%             0           0       0       0        0        0       ]
%  L=[ Lsp   0    0    0     Mp   0 ;
%       0   Lsp   0    0     0    Mp;
%       0    0   Lsc   0    -Mc   0 ;
%       0    0    0   Lsc    0    Mc;
%       Mp   0   -Mc   0     Lr   0 ;
%       0    Mp   0    Mc    0    Lr  ]
Rp=0.81;
Rc=0.81;
Lsp=80e-3;
Lsc=630e-3;
Mp=0.89e-3;
Mc=4.3e-3;
Pp=3;
Pc=1;
Lr=0.04e-3;
Rr=1.57e-3;

switch flag,
  %%%%%%%%%%%%%%%%%%
  % Initialization %
  %%%%%%%%%%%%%%%%%%
  case 0     
    [sys,x0,str,ts] = mdlInitializeSizes;                                
  %%%%%%%%%%%%%%%
  % Derivatives %
  %%%%%%%%%%%%%%%
  case 1,
    sys = mdlDerivatives(t,x,u);
  %%%%%%%%%%%
  % Outputs %
  %%%%%%%%%%%
  case 3,
    sys = mdlOutputs(t,x,u);
  %%%%%%%%%%%%%
  % Terminate %
  %%%%%%%%%%%%%
case{2,4,9}
sys=[]; % Unused flags
otherwise
error(['Unhandled flag=',num2str(flag)]); % Error handling
end
%end simom
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts] = mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates  = 7;  % 有iqp, idp, icp ,idc ,iqr, idr,w
sizes.NumDiscStates  = 0;
sizes.NumOutputs     = 4;  %输出有Te,w,iqp ,idp
sizes.NumInputs      = 5;  % 输入有uqp ,udp, uqc, udc ,TL
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0  = zeros(7,1);
str = [ ];
ts  = [0 0];
% end mdlInitializeSizes
%
%=============================================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=============================================================================
%
function sys = mdlDerivatives(t,x,u)
J=0.038;
w=x(7);
  R=[Rp 0 0 0 0 0;
    0 Rp 0 0 0 0;
    0 0 Rc 0 0 0;
    0 0 0 Rc 0 0;
    0 0 0 0 Rr 0;
    0 0 0 0 0 Rr];
  G=[ 0 Pp*Lsp*w 0 0 0 Pp*Mp*w;
      -Pp*Lsp*w 0 0 0 -Pp*Mp*w 0;
      0 0 0 Pc*Lsc* 0 Pc*Mc*w;
      0 0 -Pc*Lsc*w 0 Pc*Mc*w 0;
      0 0 0 0 0 0;
      0 0 0 0 0 0]
  L=[ Lsp   0    0    0     Mp   0 ;
       0   Lsp   0    0     0    Mp;
       0    0   Lsc   0    -Mc   0 ;
       0    0    0   Lsc    0    Mc;
       Mp   0   -Mc   0     Lr   0 ;
       0    Mp   0    Mc    0    Lr  ];
   u=[u(1);u(2);u(3);u(4);0;0]
   sys(1:6)=-inv(L)*(R+G)*x(1:6)+-inv(L)*u;
   Te=Pp*Mp*[x(1)*x(6)-x(2)*x(5)]+Pc*Mc*[x(3)*x(6)+x(4)*x(5)];
   
   sys(7)=(Te-u(5))/J;

% end mdlDerivatives
%
%=============================================================================
% mdlOutputs
% Return the output vector for the S-function
%=============================================================================
%
function sys = mdlOutputs(t,x,u)
sys(1)=Pp*Mp*[x(1)*x(6)-x(2)*x(5)]+Pc*Mc*[x(3)*x(6)+x(4)*x(5)];
sys(2)=x(7);
sys(3:4)=x(1:2);
% end mdlOutputs
1.JPG

评分

1

查看全部评分

发表于 2007-6-22 12:57 | 显示全部楼层
是红字的地方:lol :lol
function [sys,x0,str,ts] = BDFM(t,x,u,flag)
%SIMOM Example state-space M-file S-function with internal A,B,C,D matrices
%   This S-function implements a system described by state-space equations:
%   
%           dx/dt = A*x + B*u
%               y = C*x + D*u
%   
%   where x is the state vector, u is vector of inputs, and y is the vector
%   of outputs. The matrices, A,B,C,D are embedded into the M-file.
%   
%   See sfuntmpl.m for a general S-function template.
%
%   See also SFUNTMPL.
   
%电机的数学模型为
%  [iqp' idp' icp' idc' iqr' idr']'=-inv(L)*[R+G]*[iqp idp icp idc iqr idr]'+inv(L)*[uqp udp uqc udc uqr  udr]';
%   uqr=0,  udr=0
%  R=[Rp 0 0 0 0 0;
%     0 Rp 0 0 0 0;
%     0 0 Rc 0 0 0;
%     0 0 0 Rc 0 0;
%     0 0 0 0 Rr 0;
%     0 0 0 0 0 Rr]
%  G=[        0       Pp*Lsp*w    0       0        0     Pp*Mp*w;
%        -Pp*Lsp*w        0       0       0    -Pp*Mp*w     0     ;
%             0           0       0   Pc*Lsc*w     0     Pc*Mc*w  ;
%             0           0   -Pc*Lsc*w   0     Pc*Mc*w     0]    ;
%             0           0       0       0        0        0     ;
%             0           0       0       0        0        0       ]
%  L=[ Lsp   0    0    0     Mp   0 ;
%       0   Lsp   0    0     0    Mp;
%       0    0   Lsc   0    -Mc   0 ;
%       0    0    0   Lsc    0    Mc;
%       Mp   0   -Mc   0     Lr   0 ;
%       0    Mp   0    Mc    0    Lr  ]
Rp=0.81;
Rc=0.81;
Lsp=80e-3;
Lsc=630e-3;
Mp=0.89e-3;
Mc=4.3e-3;
Pp=3;
Pc=1;
Lr=0.04e-3;
Rr=1.57e-3;

switch flag,
  %%%%%%%%%%%%%%%%%%
  % Initialization %
  %%%%%%%%%%%%%%%%%%
  case 0     
    [sys,x0,str,ts] = mdlInitializeSizes;                                
  %%%%%%%%%%%%%%%
  % Derivatives %
  %%%%%%%%%%%%%%%
  case 1,
    sys = mdlDerivatives(t,x,u);
  %%%%%%%%%%%
  % Outputs %
  %%%%%%%%%%%
  case 3,
    sys = mdlOutputs(t,x,u);
  %%%%%%%%%%%%%
  % Terminate %
  %%%%%%%%%%%%%
case{2,4,9}
sys=[]; % Unused flags
otherwise
error(['Unhandled flag=',num2str(flag)]); % Error handling
end
%end simom
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts] = mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates  = 7;  % 有iqp, idp, icp ,idc ,iqr, idr,w
sizes.NumDiscStates  = 0;
sizes.NumOutputs     = 4;  %输出有Te,w,iqp ,idp
sizes.NumInputs      = 5;  % 输入有uqp ,udp, uqc, udc ,TL
sizes.DirFeedthrough = 0;
sizes.NumSampleTimes = 1;
sys = simsizes(sizes);
x0  = zeros(7,1);
str = [ ];
ts  = [0 0];
% end mdlInitializeSizes
%
%=============================================================================
% mdlDerivatives
% Return the derivatives for the continuous states.
%=============================================================================
%
function sys = mdlDerivatives(t,x,u)
J=0.038;
w=x(7);
  R=[Rp 0 0 0 0 0;
    0 Rp 0 0 0 0;
    0 0 Rc 0 0 0;
    0 0 0 Rc 0 0;
    0 0 0 0 Rr 0;
    0 0 0 0 0 Rr];
  G=[ 0 Pp*Lsp*w 0 0 0 Pp*Mp*w;
      -Pp*Lsp*w 0 0 0 -Pp*Mp*w 0;
      0 0 0 Pc*Lsc* 0 Pc*Mc*w;
      0 0 -Pc*Lsc*w 0 Pc*Mc*w 0;
      0 0 0 0 0 0;
      0 0 0 0 0 0]
  L=[ Lsp   0    0    0     Mp   0 ;
       0   Lsp   0    0     0    Mp;
       0    0   Lsc   0    -Mc   0 ;
       0    0    0   Lsc    0    Mc;
       Mp   0   -Mc   0     Lr   0 ;
       0    Mp   0    Mc    0    Lr  ];
   u=[u(1);u(2);u(3);u(4);0;0]
   sys(1:6)=-inv(L)*(R+G)*x(1:6)+-inv(L)*u;
   Te=Pp*Mp*[x(1)*x(6)-x(2)*x(5)]+Pc*Mc*[x(3)*x(6)+x(4)*x(5)];
   
   sys(7)=(Te-u(5))/J;

% end mdlDerivatives
%
%=============================================================================
% mdlOutputs
% Return the output vector for the S-function
%=============================================================================
%
function sys = mdlOutputs(t,x,u)
sys(1)=Pp*Mp*[x(1)*x(6)-x(2)*x(5)]+Pc*Mc*[x(3)*x(6)+x(4)*x(5)];
sys(2)=x(7);
sys(3:4)=x(1:2);
% end mdlOutputs
发表于 2007-7-3 17:34 | 显示全部楼层
和我返的一样的毛病:)
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

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

GMT+8, 2024-5-15 11:56 , Processed in 0.068849 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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