📄 s_xmp1.m
字号:
function [sys,x0,str,ts] = s_xmp1(t,x,u,flag)% S-file example 1% This is an S-file subsystem with no states. It performs % the algebraic function y = u(1) + u(2)^2. There are two % inputs and one output.%% Based on sfuntmpl.m, supplied with SIMULINK% Copyright (c) 1990-96 by The MathWorks, Inc.%switch flag, case 0, % Initialization [sys,x0,str,ts]=mdlInitializeSizes; case 1, % Compute derivatives of continuous states sys=mdlDerivatives(t,x,u); case 2, sys=mdlUpdate(t,x,u); case 3, sys=mdlOutputs(t,x,u); % Compute output vector case 4, % Compute time of next sample sys=mdlGetTimeOfNextVarHit(t,x,u); case 9, % Finished. Do any needed sys=mdlTerminate(t,x,u); otherwise % Invalid input error(['Unhandled flag = ',num2str(flag)]);end%***************************************************************%* mdlInitializeSizes *%***************************************************************function [sys,x0,str,ts]=mdlInitializeSizes()% Return the sizes of the system vectors, initial conditions, and% the sample times and offets.sizes = simsizes; % Create the sizes structuresizes.NumContStates = 0;sizes.NumDiscStates = 0;sizes.NumOutputs = 1;sizes.NumInputs = 2;sizes.DirFeedthrough = 1;sizes.NumSampleTimes = 1; % at least one sample time is neededsys = simsizes(sizes); % load sys with the sizes structurex0 = []; % Specify initial conditions for all states str = []; % str is always an empty matrixts = [0 0]; %initialize the array of sample times%***************************************************************%* mdlDerivatives *%***************************************************************function sys=mdlDerivatives(t,x,u)% Compute derivatives of continuous statessys = []; % Empty since this S-file has no continuous states%***************************************************************%* mdlUpdate *%***************************************************************function sys=mdlUpdate(t,x,u)% Compute update for discrete states. If necessary, check for % sample time hits.sys = []; % Empty since this model has no discrete states.%***************************************************************%* mdlOutputs *%***************************************************************function sys=mdlOutputs(t,x,u)% Compute output vector given current state, time, and inputsys = [u(1) + u(2).^2];%***************************************************************%* mdlGetTimeOfNextVarHit *%***************************************************************function sys=mdlGetTimeOfNextVarHit(t,x,u)% Return the time of the next hit for this block. Note that % the result is absolute time. Note that this function is only % used when you specify a variable discrete-time sample time sampleTime = [];%***************************************************************%* mdlTerminate *%***************************************************************function sys=mdlTerminate(t,x,u)% Perform any necessary tasks at the end of the simulationsys = [];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -