User`s guide
1 Overview of S-Functions
1-4
When to Use an S-Function
The most common use of S-functions i s to create custom Simulink blocks. You
can use S -functions for a variety of applications, including:
• Adding new g eneral purpose blocks to Simuli nk
• Incorporating existing C code into a simulation
• Describing a system as a mathematical set of equations
• Using graphical animations (see the inverted pendulum demo,
penddemo)
Anadvantageof usingS-functions isthatyou canbuild ageneral purposeblock
that you can use many times in a model, varying parameters with each
instance of the block.
How S-Functions Work
Each block w ithin a Simulink model has the following general charact erist ics:
a vector of inputs, u, a vector of outputs, y, and a vector of states, x,asshown
by this ill ustration:
The state vector may consist of continuous states, discrete states, o r a
combination of both. The mathematical relationships between the inputs,
outputs, and the states are expressed b y the following equations:
In M-file S-fun ctions, Simulink p artitions the state vector into two parts: the
continuous states and the discrete states. The continuous states occupy the
firstpart of the state vector,and the discrete states occupythe secondpart. For
x
(states)
uy
(input) (output)
(output)
(derivative)
(update)
where xx
c
x
d
+=
yf
0
txu,,()=
x
·
c
f
d
txu,,()=
x
d
k1+
f
u
txu,,()=