Clear Filters
Clear Filters

Hello i have a problem with my S function the erroe is :'Error using PMSMMainprog (line 52) State derivatives returned by S-function 'PMSMach' in 'PMSMpanel/Induction machine/S-Function' during flag=1 call must be a real vector of length 4' this is m

2 views (last 30 days)
Hello i have a problem with my S function the erroe is :'Error using PMSMMainprog (line 52) State derivatives returned by S-function 'PMSMach' in 'PMSMpanel/Induction machine/S-Function' during flag=1 call must be a real vector of length 4' this is my code: function [sys,x0,str,ts] =PMSMach(t,x,u,flag,Rs,Lsd,Lsq,fluxm,np,J,B,xi) %CSFUNC An example M-file S-function for defining a continuous system. % Example M-file S-function implementing continuous equations: % x' = Ax + Bu % y = Cx + Du % See sfuntmpl.m for a general S-function template. switch flag,
%%%%%%%%%%%%%%%%%%
% Initialization %
%%%%%%%%%%%%%%%%%%
case 0,
[sys,x0,str,ts]=mdlInitializeSizes(t,x,u,flag,Rs,Lsd,Lsq,fluxm,np,J,B,xi);
%%%%%%%%%%%%%%%
% Derivatives %
%%%%%%%%%%%%%%%
case 1,
sys=mdlDerivatives(t,x,u,flag,Rs,Lsd,Lsq,fluxm,np,J,B,xi);
%%%%%%%%%%%
% Outputs %
%%%%%%%%%%%
case 3,
sys=mdlOutputs(t,x,u,flag,Rs,Lsd,Lsq,fluxm,np,J,B,xi);
%%%%%%%%%%%%%%%%%%%
% Unhandled flags %
%%%%%%%%%%%%%%%%%%%
case { 2, 4, 9 },
sys = [];
%%%%%%%%%%%%%%%%%%%%
% Unexpected flags %
%%%%%%%%%%%%%%%%%%%%
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
% end csfunc
%
%=============================================================================
% mdlInitializeSizes
% Return the sizes, initial conditions, and sample times for the S-function.
%=============================================================================
%
function [sys,x0,str,ts]=mdlInitializeSizes(t,x,u,flag,Rs,Lsd,Lsq,fluxm,np,J,B,xi)
sizes = simsizes; sizes.NumContStates = 4; sizes.NumDiscStates = 0; sizes.NumOutputs = 6; sizes.NumInputs = 3; sizes.DirFeedthrough = 0; sizes.NumSampleTimes = 1;
sys = simsizes(sizes); x0 = xi; str = []; ts = [0 0]; % end mdlInitializeSizes % %============================================================================= % mdlDerivatives % Return the derivatives for the continuous states. %============================================================================= % function sys=mdlDerivatives(t,x,u,flag,Rs,Lsd,Lsq,fluxm,np,J,B,xi)
%state variables: isd=x(1); isq=x(2); wr=x(3); theta=x(4);
% input signals: usd=u(1); usq=u(2); TL_extra=u(3);
Tem=((3*np*fluxm*isq)/2); Ter=((3*np*(Lsd-Lsq)*isd*isq)/2); Te=(3/2)*np*((fluxm*isq)+(Lsd-Lsq)*isd*isq); TL=B*(wr/np)+TL_extra;
sys(1)=((usd+(wr*Lsq*isq)-(Rs*isd))/Lsd); sys(2)=((usq-(wr*fluxm)-(wr*Lsd*isd)-(Rs*isq))/Lsq); sys(3)=((np/J)*(Te-TL)); sys(4)=wr;
% end mdlDerivatives % %============================================================================= % mdlOutputs % Return the block outputs. %============================================================================= % function sys=mdlOutputs(t,x,u,flag,Rs,Lsd,Lsq,fluxm,np,J,B,xi)
isd=x(1); isq=x(2); wr=x(3); theta=x(4);
Tem=((3*np*fluxm*isq)/2); Ter=((3*np*(Lsd-Lsq)*isd*isq)/2); Te=Tem+Ter;
sys = [isd,isq,Tem,Ter,wr/np,theta/np]; % end mdlOutputs i do not know what the problem is can you please help me

Answers (0)

Categories

Find more on Block and Blockset Authoring in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!