Compute state-space model of linear electrical circuit
You must call
power_statespace with a minimum
of seven input arguments.
[A,B,C,D,states,x0,x0sw,rlsw,u,x,y,freq,Asw,Bsw,Csw,Dsw,Hlin] = power_statespace(rlc,switches,source,line_dist,yout,y_type,unit )
You can also specify optional arguments. To use these optional arguments, the number of input arguments must be 12, 13, 14 or 16.
[A,B,C,D,states,x0,x0sw,rlsw,u,x,y,freq,Asw,Bsw,Csw,Dsw,Hlin] = power_statespace(rlc,switches,source,line_dist,yout,y_type,unit , net_arg1,net_arg2,net_arg3,...,netsim_flag,fid_outfile, freq_sys,ref_node,vary_name,vary_val)
power_statespace command computes the
state-space model of a linear electrical circuit expressed as
where x is the vector of state-space variables (inductor currents and capacitor voltages), u is the vector of voltage and current inputs, and y is the vector of voltage and current outputs.
When you build a circuit from Simscape™
Power Systems™ Specialized
power_statespace is automatically
called by the
also available as a stand-alone command for expert users. This allows
you to generate state-space models without using the Simscape
Power Systems Specialized
Technology block modeling interface and to access options that are
not available through the Specialized Technology library. For example,
power_statespace, you can model transformers
and mutual inductances with more than three windings.
The linear circuit can contain any combination of voltage and current sources, RLC branches, multiwinding transformers, mutually coupled inductances, and switches. The state variables are inductor currents and capacitor voltages.
The state-space representation (matrices A,B,C,D, and vector
power_statespace can then be used in
a Simulink® system, via a State-Space block, to perform simulation
of the electrical circuit (see Examples). Nonlinear elements (mechanical
or power electronic switches, transformer saturation, machines, distributed
parameter lines, etc.) can be connected to the linear circuit.
These Simulink models are interfaced with the linear circuit through voltage outputs and current inputs of the state-space model. You can find the models of the nonlinear elements provided with Simscape Power Systems software in the Specialized Technology library.
The number of input arguments must be 7, 12, 13, 14, or 16. Arguments 8 to 16 are optional. The first seven arguments that must be specified are
rlc: Branch matrix specifying the
network topology as well as the resistance R, inductance L, and capacitance
C values. See format below.
switches: Switch matrix. Specify
an empty variable if no switches are used. See format below.
source: Source matrix specifying
the parameters of the electrical voltage and current sources. Specify
an empty variable if no sources are used. See format below.
line_dist: Distributed parameter
line matrix. Specify an empty variable if no distributed lines are
used. See format below.
yout: Matrix of output, expressed
as character vectors. See format below.
y_type: Integer vector indicating
output types (
0 for voltage output,
unit: Character vector specifying
the units to be used for R, L, and C values in the
unit = 'OHM', R L C values are specified in
ohms Ω at the fundamental frequency specified by
value is 60 Hz). If
unit = 'OMU', R L C values
are specified in ohms (Ω), millihenries (mH), and microfarads
The last nine arguments are optional. The first three are used
to pass arguments from the
Hereafter, only the arguments to be specified when
used as a stand-alone command are described:
Used to pass arguments from
an empty variable
 for each of these arguments.
netsim_flag: Integer controlling
the messages displayed during the execution of
Default value is
netsim_flag = 0, the version number, number
of states, inputs, outputs, and modes are displayed. Output values
are displayed in polar form for each source frequency.
netsim_flag = 1, only version number,
number of states, inputs, and outputs are displayed.
netsim_flag = 2, no message is displayed
fid_outfile: File identifier of
power_statespace output file containing parameter
values, node numbers, steady-state outputs, and special messages.
Default value is
freq_sys: Fundamental frequency
(Hz) considered for specification of XL and
XC reactances if
'OHM'. Default value is 60 Hz.
ref_node: Reference node number
used for ground of PI transmission lines. If
specified, the user is prompted to specify a node number.
vary_name: Matrix containing the
symbolic variable names used in output, expressed as character vectors.
These variables must be defined in your MATLAB® workspace.
vary_val: Vector containing the
values of the variable names specified in
A,B,C,D: state-space matrices of
the linear circuit with all switches open.
A(nstates, nstates) , B(nstates, ninput), C(noutput, nstates) , D(noutput, ninput),
nstates is the number of state variables,
the number of inputs, and
noutput is the number
states: Matrix containing the names
of the state variables. Each name has the following format:
xx = branch number zz1 = first node number of the branch zz2 = second node number of the branch
The last lines of the
states matrix, which
are followed by an asterisk, indicate inductor currents and capacitor
voltages that are not considered as state variables. This situation
arises when inductor currents or capacitor voltages are not independent
(inductors forming a cut set – for example, inductors connected
in series – or capacitors forming a loop). The currents and
voltages followed by asterisks can be expressed as a linear combination
of the other state variables:
x0: Column vector of initial values
of state variables considering the open or closed status of switches.
x0sw: Vector of initial values
of switch currents.
rlsw: Matrix (
containing the R and L values of series switch impedances in ohms
(Ω) and henries (H).
nswitch is the number
of switches in the circuit.
containing the steady-state complex values of inputs, states, and
nfreq is the length of the
Each column corresponds to a different source frequency, as specified
by the next argument,
freq: Column vector containing
the source frequencies ordered by increasing frequency.
Asw,Bsw,Csw,Dsw: State-space matrices
of the circuit including the closed switches. Each closed switch with
an internal inductance adds one extra state to the circuit.
Hlin: Three-dimensional array (
nfreq complex transfer impedance matrices
of the linear system corresponding to each frequency of the
Two formats are allowed:
Six columns: Implicit branch numbering. Branch numbers correspond to the RLC line numbers.
Seven columns: Explicit branch numbering. Branch number
assigned by the user.
Each line of the
RLC matrix must be specified
according to the following format.
[node1, node2, type, R, L, C, Nobr] for RLC
branch or line branch
[node1, node2, type, R, L, C, Nobr] for transformer
[node1, node2, type, R, L, U, Nobr] for transformer
[node1, node2, type, R, L, U, Nobr] for mutual
node1: First node number of the
branch. The node number must be positive or zero. Decimal node numbers
node2: Second node number of the
branch. The node number must be positive or zero. Decimal node numbers
type: Integer indicating the type
of connection of RLC elements, or, if negative, the transmission line
type = 0: Series RLC element
type = 1: Parallel RLC element
type = 2: Transformer winding
type = 3: Coupled (mutual) winding
type is negative, the transmission line
is modeled by a PI section of length
For a mutual inductor or a transformer having N windings, N+1
consecutive lines must be specified in
N lines with
type = 2 or
= 3; (one line per winding). Each line specifies
R/L, R/Xl = winding resistance and leakage reactance
for a transformers or winding resistance and self reactance for mutually
U is the nominal voltage of transformer
winding (specify 0 if
type = 3).
One extra line with
1 for the magnetizing branch of a transformer (parallel
or one line with
type = 0 for a mutual impedance
For a transformer magnetizing branch or a mutual impedance, the first node number is an internal node located behind the leakage reactance of the first winding. The second node number must be the same as the second node number of the first winding.
To model a saturable transformer, you must use a nonlinear inductance
instead of the linear inductance simulating the reactive losses. Set
Lm/Xm value to
0 (no linear
inductance) and use the Saturable Transformer block,
set with proper flux-current characteristics.
This block can be found in the Fundamental Blocks/Elements library. It must be connected to the linear part of the system (State-Space block or S-function) between a voltage output (voltage across the magnetizing branch) and a current input (current source injected into the transformer internal node). See the Examples.
If type is negative, its absolute value specifies the length (km) of a transmission line simulated by a PI section. For a transmission line, the R/L/C or R/Xl/Xc values must be specified in Ω/km, mH/km, and µF/km, or in Ω/km.
Branch resistance (Ω)
Branch inductive reactance (Ω at
Branch inductance (mH)
Branch capacitive reactance (Ω at
Nominal voltage of transformer winding. The same units
(volts or kV) must be used for each winding. For a mutual inductance
Zero value for
The following restrictions apply for transformer winding R-L
values. Null values are not allowed for secondary impedances if some
transformer secondaries form loops (as in a three-phase delta connection).
Specify a very low value for R or L or both (e.g.,
based on rated voltage and power) to simulate a quasi-ideal transformer.
The resistive and inductive parts of the magnetizing branch can be
set to infinite (no losses; specify
Xm = Rm = inf).
Three formats are allowed:
Five columns: All sources are generating the same
frequency specified by
Six columns: The frequency of each source is specified in column 6.
Seven columns: The seventh column is used to specify the type of nonlinear element modeled by the current source.
Each line of the source matrix must be specified according to the following format:
[ node1, node2, type, amp, phase, freq, model ]
Node numbers corresponding to the source terminals. These are the
node1 is the positive
Current source: Positive current flowing from
type: Integer indicating the type
0 for voltage source,
amp: Amplitude of the AC or DC
voltage or current (V or A).
phase: Phase of the AC voltage
or current (degree).
freq: Frequency (Hz) of the generated
voltage or current. Default value is 60 Hz. For a DC voltage or current
be set to a negative value. The generated signals are
amp * sin(2π*freq*t + phase)for AC,
model: Integer specifying the type
of nonlinear element modeled by the current source (saturable inductance,
thyristor, switch,...). Used by
The commands that compute the state-space representation of a system expect the sources in a certain order. You must respect this order in order to obtain correct results. You must be particularly careful if the system contains any switches. This is the proper ordering of sources:
The currents from all switches that have a null inductance (Lon = 0), if any.
The currents from all nonlinear models that have a finite inductance (switches with Lon > 0, the magnetizing inductance in saturable transformers, etc.), if any.
All other voltage and current sources in any order, if any.
Refer to the Example section below for an example illustrating proper ordering of sources for a system containing nonlinear elements.
Switches are nonlinear elements simulating mechanical or electronic devices such as circuit breakers, diodes, or thyristors. Like other nonlinear elements, they are simulated by current sources driven by the voltage appearing across their terminals. Therefore, they cannot have a null impedance. They are simulated as ideal switches in series with a series R-L circuit. Various models of switches (circuit breaker, ideal switch, and power electronic devices) are available in the Simscape Power Systems Specialized Technology library. They must be interconnected to the linear part of the system through appropriate voltage outputs and current inputs.
The switch parameters must be specified in a line of the switches matrix in seven different columns, according to the following format.
[ node1, node2, status, R, L/Xl, no_I , no_U ]
Node numbers corresponding to the switch terminals
Code indicating the initial status of the switch at t
Resistance of the switch when closed (Ω)
Inductance of the switch when closed (mH) or inductive reactance (Ω at freq_sys)
For these last two fields, you must use the same units as those specified for the RLC matrix. Either field can be set to 0, but not both.
The next two fields specify the current input number and the voltage output number to be used for interconnecting the switch model to the State-Space block. The output number corresponding to the voltage across a particular switch must be the same as the input number corresponding to the current from the same switch (see Example section below):
no_I: Current input number coming
from the output of the switch model
no_U: Voltage output number driving
the input of the switch model
The distributed parameter line model contains two parts:
A linear part containing current sources and resistances that are connected at the line sending and receiving buses together with the linear circuit.
A nonlinear part available in the Distributed Parameter Line
block of the Elements library. This block performs the phase-to-mode
transformations of voltage and currents and simulates the transmission delays
for each mode. The distributed_param_line block must be
connected to appropriate voltage outputs and current inputs of the linear part
of the system. The line parameters have to be specified in the
line_dist matrix and also in the Distributed Parameter
Each row of the
line_dist matrix is used to specify a distributed parameter
transmission line. The number of columns of
line_dist depends on the
number of phases of the transmission line.
nphase line, the first (
+ 3 * nphase + nphase^2) columns are used. For example,
for a three-phase line, 22 columns are used.
[nphase, no_I, no_U, length, L/Xl, Zc, Rm, speed, Ti]
Number of phases of the transmission line
Input number in the source matrix corresponding to the
first current source Is_1 of the line model. Each line model uses
2*nphase current sources specified in the source matrix as follows:
Output number of the state-space corresponding to the
first voltage output Vs_1 feeding the line model. Each line model
uses 2*nphase voltage outputs in the source matrix as follows:
Length of the line (km)
Vector of the nphase modal characteristic impedances (Ω)
Vector of the nphase modal series resistances (Ω/km)
Vector of the nphase modal propagation speeds (km/s)
Transformation matrix from mode to phase currents such
that Iphase = Ti * Imod. The nphase * nphase matrix must be given
in vector format,
The desired outputs are specified by the matrix
Each line of the
yout matrix must be an algebraic
expression containing a linear combination of states and state derivatives,
specified according to the following format.
Capacitor voltage of branch n
Inductor current of branch n
Source voltage or current specified by line n of the source matrix
Voltage between nodes x1 and x2 = Ux1 −Ux2
Current in branch n flowing from
node1 to node2 (See format of RLC matrix). For a parallel RLC branch,
Current flowing into node x of a PI transmission line specified by line n of the RLC matrix. This current includes the series inductive branch current and the capacitive shunt current.
Each output expression is built from voltage and current variable
names defined above, their derivatives, constants, other variable
names, parentheses and operators
(+ − * / ^),
in order to form a valid MATLAB expression. For example
yout = char(['R1*I_b1+Uc_b3-L2*dIl_b2','U_n10_20','I2+3*I_b5']);
If variable names are used (
the above example), their names and values must be specified by the
two input arguments
Branch current, inductor current of branch n,
or current of source #n is oriented from
Current at one end (node x) of a PI transmission line.
If x =
Voltage across capacitor or source voltage
Voltage between nodes x1 and x2 = Ux1 − Ux2.
The commands that compute the state-space representation of a system expect the outputs to be in a certain order. You must respect this order in order to obtain correct results. You must be particularly careful if the system contains any switches. The following list gives the proper ordering of outputs:
The voltages across all switches that have a null inductance (Lon = 0), if any
The currents of all switches that have a null inductance (Lon = 0), if any, in the same order as the voltages above
The voltages across all nonlinear models that have a finite inductance (switches with Lon > 0, the magnetizing inductance in saturable transformers, etc.)
All other voltage and current measurements that you request, in any order
Refer to the Example section below for an example illustrating proper ordering of outputs for a system containing nonlinear elements.
The following circuit consists of two sources (one voltage source
and one current source), two series RLC branches (
two parallel RLC branches (
one saturable transformer, and two switches (
initially closed whereas
Sw2 is initially open.
Three measurement outputs are specified (I1, V2, and V3). This circuit
has seven nodes numbered 0, 1, 2, 2.1, 10, 11, and 12. Node 0 is used
for the ground. Node 2.1 is the internal node of the transformer where
the magnetization branch is connected.
You can use the
to find the state-space model of the linear part of the circuit. The
Lsat must be modeled separately by means of
current sources driven by the voltages appearing across their terminals.
Therefore you must provide three additional current sources and three
additional voltage outputs for interfacing the nonlinear elements
to the linear circuit.
You can find the state-space model of the circuit by entering
the following commands in a MATLAB script file. The example is
available in the
Notice that an output text file named
information on the system is requested in the call to
unit='OMU'; % Units = ohms, mH, and uF rlc=[ %N1 N2 type R L C(uF)/U(V) 1 2 0 0.1 1 0 %R1 L1 2 0 2 0.05 1.5 100 %transfo Wind.#1 10 0 2 0.20 0 200 %transfo Wind.#2 2.1 0 1 1000 0 0 %transfo mag. branch 11 0 1 200 0 1 %R5 C5 11 12 0 0 0 1e-3 %C6 12 0 1 0 500 2 %L7 C7 ]; source=[ %N1 N2 type U/I phase freq 10 11 1 0 0 0 %Sw1 11 12 1 0 0 0 %Sw2 2.1 0 1 0 0 0 %Saturation 1 0 0 100 0 60 %Voltage source 0 10 1 2 -30 180 %Current source ]; switches=[ %N1 N2 status R(ohm) L(mH) I# U# # 10 11 1 0.01 0 1 1 %Sw1 11 12 0 0.1 0 2 2 %Sw2 ]; %outputs % % Both switches have Lon=0, so their voltages must be the first outputs, % immediately followed by their currents (in the same order as the voltages). % The voltage across all nonlinear models that don't have L=0 follow % (in this case the saturable transformer's magnetizing inductor). % The measurements that you request follow, in any order. % y_u1='U_n10_11'; %U_Sw1= Voltage across Sw1 y_u2='U_n11_12'; %U_Sw2= Voltage across Sw2 y_i3='I1'; %I1= Switch current Sw1 y_i4='I2'; %I2= Switch current Sw2 y_u5='U_n2.1_0'; %U_sat= Voltage across saturable reactor y_i6='I_b1'; %I1 measurement y_u7='U_n11_0'; %V2 measurement y_u8='U_n12_0'; %V3 measurement yout=char(y_u1,y_u2,y_i3,y_i4,y_u5,y_i6,y_u7,y_u8); % outputs y_type=[0,0,1,1,0,1,0,0]; %output types; 0=voltage 1=current % Open file that contains power_statespace output information fid=fopen('power_circ2ss.net','w'); [A,B,C,D,states,x0,x0sw,rlsw,u,x,y,freq,Asw,Bsw,Csw,Dsw,Hlin]= power_statespace(rlc,switches,source,,yout,y_type,unit,,, ,0,fid);
power_statespace is executing, the
following messages are displayed.
Computing state space representation of linear electrical circuit (V2.0)... (4 states ; 5 inputs ; 7 outputs) Oscillatory modes and damping factors: F=159.115Hz zeta=4.80381e-08 Steady state outputs @ F=0 Hz : y_u1= 0Volts y_u2= 0Volts y_i3= 0Amperes y_i4= 0Amperes y_u5= 0Volts y_i6= 0Amperes y_u7= 0Volts y_u8= 0Volts Steady state outputs @ F=60 Hz : y_u1 = 0.009999 Volts < 3.168 deg. y_u2 = 199.4 Volts < -1.148 deg. y_i3 = 0.9999 Amperes < 3.168 deg. y_i4 = 0 Amperes < 0 deg. y_u5 = 99.81 Volts < -1.144 deg. y_i6 = 2.099 Amperes < 2.963 deg. y_u7 = 199.4 Volts < -1.148 deg. y_u8 = 0.01652 Volts < 178.9 deg. Steady state outputs @ F=180 Hz : y_u1 = 0.00117 Volts < 65.23 deg. y_u2 = 22.78 Volts < 52.47 deg. y_i3 = 0.117 Amperes < 65.23 deg. y_i4 = 0 Amperes < 0 deg. y_u5 = 11.4 Volts < 53.48 deg. y_i6 = 4.027 Amperes < 146.5 deg. y_u7 = 22.83 Volts < 52.47 deg. y_u8 = 0.0522 Volts < 52.47 deg.
The names of the state variables are returned in the
states states = Il_b2_n2_2.1 Uc_b5_n11_0 Uc_b6_n11_12 Il_b7_n12_0 Il_b1_n1_2* Uc_b7_n12_0*
Although this circuit contains a total of six inductors and
capacitors, there are only four state variables. The names of the
state variables are given by the first four lines of the
The last two lines are followed by an asterisk indicating that these
two variables are a linear combination of the state variables. The
dependencies can be viewed in the output file
The following capacitor voltages are dependent: Uc_b7_n12_0 = + Uc_b5_n11_0 - Uc_b6_n11_12 The following inductor currents are dependent: Il_b1_n1_2 = + Il_b2_n2_0
The A,B,C,D matrices contain the state-space model of the circuit
without nonlinear elements (all switches open). The
contains the initial state values considering the switch Sw1 closed.
Dsw matrices contain the state-space model
of the circuit considering the closed switch
x0sw vector contains the initial current in
the closed switch.
A A = -4.0006e+05 0 0 0 0 -4995 0 -499.25 0 -4992.5 0 4.9925e+05 0 2 -2 0 Asw Asw = -80.999 -199.99 0 0 4.9947e+05 -5244.7 0 -499.25 4.9922e+05 -5242.1 0 4.9925e+05 0 2 -2 0
The system source frequencies are returned in the
freq freq = 0 60 180
The corresponding steady-state complex outputs are returned
in the (6-by-3)
y matrix where each column corresponds
to a different source frequency.
For example, you can obtain the magnitude of the six voltage and current outputs at 60 Hz as follows.
abs(y(:,2)) ans = 0.0099987 199.42 0.99987 0 99.808 2.0993 199.41 0.016519
The initial values of the four state variables are returned
x0 vector. You must use this vector in the
State-Space block to start the simulation in steady state.
x0 x0 = 2.3302 14.111 14.07 3.1391e-05
The initial values of switch currents are returned in
To start the simulation in steady state, you must use these values
as initial currents for the nonlinear model simulating the switches.
x0sw x0sw = 0.16155 0
The Simulink diagram of the circuit is available in the
If no resistive switches had been used, the linear part of the circuit
could have been simulated with the State-Space block of the Simulink/Continuous
library. However, as resistive switches are used, the
is used instead of the State-Space block. This S-function reevaluates
the state-space matrices during simulation when the circuit topology
is changing (after a switch is opened or closed). Appropriate inputs
and outputs are used to connect the switch and saturable reactance
models to the linear system. Notice that the status of each switch
is fed back from the breaker to the S-function, after the inputs mentioned
earlier. You can find the Breaker and Saturable Transformer blocks
in the Fundamental Blocks/Elements library containing all the nonlinear
continuous models used by Simscape
Power Systems software. As the breaker
model is vectorized, a single block is used to simulate the two switches
If you use the Simscape
Power Systems Specialized Technology library
to build your circuit, the same Simulink system is generated
automatically by the
power_analyze command. The Simscape
Power Systems Specialized
Technology version of this system is also available in the