Guia 03 MathScript (2023-04-03) 09.25
Guia 03 MathScript (2023-04-03) 09.25
GUIA 03
USO DE MATHSCRIPT EN CONTROL LABVIEW
Basic Operations
Variables:
Variables are defined with the assignment operator, “=”. MathScript is dynamically typed, meaning
that variables can be assigned without declaring their type, and that their type can change. Values
can come from constants, from computation involving values of other variables, or from the output
of a function.
Example:
Vectors and Matrices
Vectors: Given the following vector:
1
𝑥= 2
3
x =[1 2 3]
Example:
This example shows how to use the colon notation creating a vector and do some calculations.
Matrices:
MathScript Code:
A=[0 1; -2 -3]
−1 2 0
𝐶= 4 10 −2
1 0 6
MathScript Code:
C=[-1 2 0; 4 10 -2; 1 0 6]
→ Find the value in the second row and the third column of matrix C:
C(2,3)
This gives:
ans =
-2
C(2,:)
This gives:
ans =
4 10 -2
C(:,3)
This gives:
ans = 0
-2
6
Deleting Rows and Columns:
You can delete rows and columns from a matrix using just a pair of square brackets [].
Example:
Given
0 1
𝐴=
−2 −3
>>A=[0 1; -2 -3];
>>A(:,2) = []
A =
0
-2
[End of Example]
Linear Algebra
Linear algebra is a branch of mathematics concerned with the study of matrices, vectors, vector
spaces (also called linear spaces) , linear maps (also called linear transformations) , and systems of
linear equations.
MathScript are well suited for Linear Algebra. Here are some useful functions for Linear Algebra in
MathScript:
Type “help matfun” (Matrix functions - numerical linear algebra) in the Command Window for more
information, or type “help elmat” (Elementary matrices and matrix manipulation).
You may also type “help <functionname>” for help about a specific function.
Plotting
MathScript has lots of functionality for Plotting. The simplest and most used is the plot function.
Example:
>>t=[0:0.1:10];
>>y=cos(t);
>>plot(t,y)
[End of Example]
y(0)
y(t) = e−ζ ωn t sin ωn 1 − ζ 2 t + θ ,
1 − ζ2
where θ = cos−1 ζ , ωn2 = k/M and 2ζ ωn = b/M. The initial displacement is y(0) and ẏ(0) = 0. The transient system response is
underdamped when ζ < 1, overdamped when ζ > 1, and critically damped when ζ = 1.
.
by ky
k
Wall
friction, b Mass y y
M M
r(t) r
Force
The LabVIEW commands to generate the plot of the unforced response are shown in Fig. 1.2.
In the LabVIEW setup, the variables y(0), ωn , ζ , and t are input to the user interface part of the VI. Then the Unforced.vi is
executed to generate the desired plots. This creates an interactive analysis capability to analyze the effects of natural frequency
and damping on the unforced response of the mass displacement. One can investigate the effects of the natural frequency and the
damping on the time response by simply entering new values of ωn and ζ and rerun the Unforced.vi. 3
For the spring-mass-damper problem, the unforced solution to the differential equation was readily available. In general, when
simulating closed-loop feedback control systems subject to a variety of inputs and initial conditions, it is difficult to obtain the solution
analytically. In these cases we can use LabVIEW to compute the solutions numerically and to display the solution graphically.
C H A P T E R 7
This chapter begins with an introduction to the Bode plot and then discusses the connection between the frequency response and
performance specifications in the time domain. We conclude with an illustrative example of designing a control system in the
frequency domain. The LabVIEW function covered is CD Bode. The CD Bode function is used to generate a Bode plot. We will
use transfer function models in this chapter, but the use of the CD Bode function is exactly the same for state variable models as
with transfer functions, except that the input is a state-space object instead of a transfer function object.
The Bode plot corresponding to Eq. (7.1) is shown in Fig. 7.1. The plot consists of the logarithmic gain in dB versus ω in one plot
and the phase φ(ω) versus ω in a second plot. As with the root locus plots, it will be tempting to rely exclusively on LabVIEW to
obtain your Bode plots. Treat LabVIEW as one tool in a tool kit that can be used to design and analyze control systems. It is essential
to develop the capability to sketch Bode plots. There is no substitute for a clear understanding of the underlying theory.
Keeping in mind the goal of designing control systems that satisfy certain performance specifications given in the time domain,
we must establish a connection between the frequency response and the transient time response of a system. The relationship between
specifications given in the time domain to those given in the frequency domain depends upon approximation of the system by a
second-order system with the poles being the system dominant poles.
Figure 7.1: The Bode plot associated with Eq. (7.1).