求助建立一个MATLAB中S函数的建立及用法

发布网友 发布时间:2022-04-24 01:28

我来回答

1个回答

热心网友 时间:2023-10-18 13:40

不知道你的u得到了没有?如果得到了,可以直接编写S函数来得到f(u)。
function [sys,x0,str,ts,simStateCompliance] = sfun(t,x,u,flag,Io,q,A,K,T)

switch flag,

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

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

case 2,
sys=mdlUpdate(t,x,u);

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

case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);

case 9,
sys=mdlTerminate(t,x,u);

otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));

end

function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes

sizes = simsizes;

sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 0;
sizes.NumInputs = 0;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed

sys = simsizes(sizes);

x0 = [];

str = [];

ts = [0 0];

simStateCompliance = 'UnknownSimState';

function sys=mdlDerivatives(t,x,u)

sys = [];

function sys=mdlUpdate(t,x,u)

sys = [];

function sys=mdlOutputs(t,x,u,Io,q,A,K,T)

sys = Io(exp(q*u/(A*K*T))-1);

function sys=mdlGetTimeOfNextVarHit(t,x,u)

sampleTime = 1; % Example, set the next hit to be one second later.
sys = t + sampleTime;

function sys=mdlTerminate(t,x,u)

sys = [];

热心网友 时间:2023-10-18 13:40

不知道你的u得到了没有?如果得到了,可以直接编写S函数来得到f(u)。
function [sys,x0,str,ts,simStateCompliance] = sfun(t,x,u,flag,Io,q,A,K,T)

switch flag,

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

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

case 2,
sys=mdlUpdate(t,x,u);

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

case 4,
sys=mdlGetTimeOfNextVarHit(t,x,u);

case 9,
sys=mdlTerminate(t,x,u);

otherwise
DAStudio.error('Simulink:blocks:unhandledFlag', num2str(flag));

end

function [sys,x0,str,ts,simStateCompliance]=mdlInitializeSizes

sizes = simsizes;

sizes.NumContStates = 0;
sizes.NumDiscStates = 0;
sizes.NumOutputs = 0;
sizes.NumInputs = 0;
sizes.DirFeedthrough = 1;
sizes.NumSampleTimes = 1; % at least one sample time is needed

sys = simsizes(sizes);

x0 = [];

str = [];

ts = [0 0];

simStateCompliance = 'UnknownSimState';

function sys=mdlDerivatives(t,x,u)

sys = [];

function sys=mdlUpdate(t,x,u)

sys = [];

function sys=mdlOutputs(t,x,u,Io,q,A,K,T)

sys = Io(exp(q*u/(A*K*T))-1);

function sys=mdlGetTimeOfNextVarHit(t,x,u)

sampleTime = 1; % Example, set the next hit to be one second later.
sys = t + sampleTime;

function sys=mdlTerminate(t,x,u)

sys = [];

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com