How to correct my s function code ?please help

when I run the simulink of tire model, it always occur :Output returned by S-function 't_dugoff' in 'untitled1/front tire model' during flag=3 call must be a real vector of length 3,
the code is like this:
function [sys,x0,str,ts] = t_dugoff(t,x,u,flag)
switch flag,
case 0,
[sys,x0,str,ts]=mdlInitializeSizes;
case 3,
sys = mdlOutputs(t,x,u);
case { 1, 2, 4, 9 }
sys=[];
otherwise
error(['Unhandled flag = ',num2str(flag)]);
end
function [sys,x0,str,ts]=mdlInitializeSizes
sizes = simsizes;
sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 3;
sizes.NumInputs = 4;
sizes.DirFeedthrough =1 ;
sizes.NumSampleTimes = 0;
sys = simsizes(sizes);
x0 = [];
str = [];
ts = [];
function sys = mdlOutputs(t,x,u)
wload=u(4);
vspd=u(2);
whlspd=u(1);
slip_A=u(3);
R=0.334;
cx=20000;
cy=16000;
fscl=0.0034;
u0=0.9;
a=slip_A*pi/180;
slip=(vspd-R*whlspd)/vspd;
uf=u0*(1-fscl*vspd*slip);
epslon=1e-6;
MAXF=uf*wload*(1-slip);
demandF=((cx*slip)^2+(cy*tan(a))^2)^0.5;
lamda=MAXF/2/demandF;
if lamda>=1
Flf=cx*slip/(1-slip);
Fyf=cy*tan(a)/(1-slip);
end
if lamda<1
Flf=cx*slip/(1-slip)*(2-lamda)*lamda;
Fyf=cy*tan(a)/(1-slip)*(2-lamda)*lamda;
end
sys=[Flf Fyf slip];

댓글 수: 2

Hadi Abbas
Hadi Abbas 2018년 4월 1일
Do you remember how you solved this problem??
What happens if lambda equals 1 exactly?. What happens if slip is 1, leading to division by 0?

댓글을 달려면 로그인하십시오.

답변 (1개)

Kaustubha Govind
Kaustubha Govind 2012년 4월 6일

2 개 추천

It looks like this line may not be returning a vector with 3 elements (because you have configured the S-function for 3 outputs) as Simulink expects:
sys=[Flf Fyf slip];
It might be that Flf, Fyf and slip are not scalars, and therefore concatenate to a vector that does not have a size equal to 3.
I would recommend setting a breakpoint at the line. Then run your model again and examine the dimensions of the intermediate variables and of the output 'sys'.

카테고리

도움말 센터File Exchange에서 General Applications에 대해 자세히 알아보기

질문:

2012년 4월 6일

댓글:

2018년 4월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by