How Can I Model A Time Varying Dynamic System in MATRIXx ?
Overview
SystemBuild includes many built-in blocks for linear time invariant systems, logical signals, matrices, algebraic expressions, trigonometric operations, and power exponential calculations. These blocks can be used to build up a wide variety of system models. When you need additional functionality beyond that which is inherent to SystemBuild, you can use a BlockScript block or link to external source code using a UserCode block (UCB).
One common class of systems is called time varying systems. Although there are not specific blocks for directly modeling time varying systems in SystemBuild, it is easy to model such systems. The following is a detailed description an example of the development and modeling of a time varying dynamic system using Xmath and SystemBuild in MATRIXx.
Table of Contents
System Summary
As an example of a time varying system, we simulate a 2nd order system with a natural frequency and damping ratio that increases with time. To simulate the system, we will represent it as a state space system with varying A and B matrices. We define multiple A and B matrices in Xmath, and then build a model in SystemBuild that uses the GainScheduler block to choose between the matrices based on time. Creating a List of Systems
You can use the following Xmath commands a list of 2nd order dynamic systems wherein both the natural frequency, omega, and the damping ratio, zeta, are varying. The following code creates four systems in a list.
n = 0;
zeta = 0;
for omega = [pi/2, pi, 2*pi, 4*pi] do
b = [ omega^2, 0 ]';
c = [ 0, 1 ];
d = 0;
n = n + 1;
s(n) = system(a,b,c,d);
zeta = zeta + 0.01;
[a2,b2] = abcd(s(2))
[a3,b3] = abcd(s(3))
[a4,b4] = abcd(s(4))
These commands are in contained in the following MathScript file.
Building a Model
The diagram we need to create will perform
y = C *x
For this example, the C matrix is non-time varying. The C matrix [0;1] is the same as choosing the second output of the integrator as the output of the model. The D matrix is null. Refer to the following figure to see the required overall diagram.
The following diagrams highlight each block in the model. Following the diagram, the parameters of each block are specified. The key parts of the model are the GainScheduler blocks. Refer to the next section for an explanation of how they work.
| Name: Simulation Time Block Type: Block Script Pallette: User Programmed Inputs: 0 Outputs: 1 Parameters: source code inputs: (); outputs: y; environment : TIME; y= TIME; | ![]() |
| Name: Time Varying A Matrix Block: GainScheduler Pallette: Logical Inputs: 3 Outputs: 2 Parameters: Break Points = [ 0, 2.5, 5.0, 7.5 ] Gain Matrices = [ a1, a2, a3, a4 ] | ![]() |
| Name: Time Varying B Matrix Block: GainScheduler Pallette: Logical Inputs: 2 Outputs: 2 Parameters: Break Points = [ 0, 2.5, 5.0, 7.5 ] Gain Matrices = [ b1, b2, b3, b4 ] | ![]() |
| Name: Sum Block: Summer Pallette: Algebraic Inputs: 2 Outputs: 2 Parameters: Signs = [1,1] Note: Output 1 and 2 from Time Varying B Matrix are inputs 1 and 2 to Sum. Output 1 and 2 from Time Varying A Matrix are inputs 3 and 4 to Sum. | ![]() |
| Name: Integrator Block: Integrator Pallette: Dynamic Inputs: 2 Outputs: 2 Parameters: (defaults) Note: Output 2 of this block is the output of the system | ![]() |
The GainScheduler Block
The GainScheduler block is designed to select a matrix at discrete time points based on some input. In this case, the input is the Simulation Time generated by the BlockScript block. The first matrix, a1, is selected for the time range [ 0 : 2.5 ) while the a2 matrix is selected for time range [ 2.5, 5.0 ) and likewise for subsequent intervals.
We can observe this artifact by performing simulations up to some point and extracting the linearized system at the end of the simulation. The linearized system should be constant in the each time range:
[ 0 : 2.5 ) ... [ 2.5 : 5.0 ) ... [ 5.0 : 7.5 ) ... [ 7.5 : 10.0 ].
Use the Tolerance parameter to provide more gradual transitions. In this case, linear interpolation is done element by element.
Simulating the System
The step response to this system can be obtained in Xmath by typing,
t = [0 : .05 : 10]';
y = sim ("Time Varying System",t,ones(t));
plot (t, y)
The response should look like the following figure.
Reader Comments | Submit a comment »
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).







