0% found this document useful (0 votes)
24 views9 pages

Guia 03 MathScript (2023-04-03) 09.25

This document provides a guide for using MathScript in LabVIEW control. It discusses basic operations in MathScript like variables, vectors, and matrices. It demonstrates how to create and manipulate vectors and matrices using MathScript code. The document also covers linear algebra functions in MathScript and how to perform operations like finding the rank, determinant, and inverse of matrices. Additionally, it discusses plotting capabilities in MathScript and provides examples of functions for creating plots like plot, figure, and axis. Finally, the document gives an overview of simulating spring-mass-damper systems using LabVIEW to visualize the unforced time response.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views9 pages

Guia 03 MathScript (2023-04-03) 09.25

This document provides a guide for using MathScript in LabVIEW control. It discusses basic operations in MathScript like variables, vectors, and matrices. It demonstrates how to create and manipulate vectors and matrices using MathScript code. The document also covers linear algebra functions in MathScript and how to perform operations like finding the rank, determinant, and inverse of matrices. Additionally, it discusses plotting capabilities in MathScript and provides examples of functions for creating plots like plot, figure, and axis. Finally, the document gives an overview of simulating spring-mass-damper systems using LabVIEW to visualize the unforced time response.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

AUTOMATIZACION INDUSTRIAL

GUIA 03
USO DE MATHSCRIPT EN CONTROL LABVIEW

In the Getting Started window, select Tools -> MathScript Window...:

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

This can be implemented in MathScript like this:

x =[1 2 3]

The “colon notation” is very useful for creating vectors:

Example:
This example shows how to use the colon notation creating a vector and do some calculations.

Matrices:

Given the following matrix:


0 1
𝐴=
−2 −3

MathScript Code:

A=[0 1; -2 -3]

Given the following matrix:

−1 2 0
𝐶= 4 10 −2
1 0 6

MathScript Code:

C=[-1 2 0; 4 10 -2; 1 0 6]

How to get a subset of a matrix:

→ Find the value in the second row and the third column of matrix C:

C(2,3)

This gives:

ans =
-2

→ Find the second row of matrix C:

C(2,:)

This gives:

ans =

4 10 -2

→ Find the third column of matrix C:

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

We define the matrix A:

>>A=[0 1; -2 -3];

To delete the second column of a matrix A, we use:

>>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:

Function Description Example


rank Find the rank of a matrix. Provides an estimate of the number of >>A=[1 2; 3 4]
>>rank(A)
linearly independent rows or columns of a matrix A.
det Find the determinant of a square matrix >>A=[1 2; 3 4]
>>det(A)
inv Find the inverse of a square matrix >>A=[1 2; 3 4]
>>inv(A)
eig Find the eigenvalues of a square matrix >>A=[1 2; 3 4]
>>eig(A)
ones Creates an array or matrix with only ones >>ones(2)
>>ones(2,1)
eye Creates an identity matrix >>eye(2)

diag Find the diagonal elements in a matrix >>A=[1 2; 3 4]


>>diag(A)

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)

This gives the following plot:

[End of Example]

MathScript has lots of built-in functions for plotting:

Function Description Example


plot Generates a plot. plot(y) plots the columns of y against the >X = [0:0.01:1];
>Y = X.*X;
indexes of the columns. >plot(X, Y)
figure Create a new figure window >>figure
>>figure(1)
subplot Create subplots in a Figure. subplot(m,n,p) or subplot(mnp), >>subplot(2,2,1)
breaks the Figure window into an m-by-n matrix of small axes,
selects the p-th axes for the current plot. The axes are counted
along the top row of the Figure window, then the second row,
etc.
grid Creates grid lines in a plot. >>grid
>>grid on
“grid on” adds major grid lines to the current plot. >>grid off
“grid off” removes major and minor grid lines from the current
plot.
axis Control axis scaling and appearance. “axis([xmin xmax ymin >>axis([xmin xmax ymin ymax])
>>axis off
ymax])” sets the limits for the x- and y-axis of the current axes. >>axis on
title Add title to current plot >>title('this is a title')
title('string')
xlabel Add xlabel to current plot >> xlabel('time')
1 Simulating Spring-Mass-Damper Systems
A spring-mass-damper mechanical system is shown in Fig. 1.1. The motion of the mass, denoted by y(t), is described by the
differential equation
M ÿ(t) + b ẏ(t) + ky(t) = r(t).
The unforced dynamic response of the spring-mass-damper mechanical system is

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.

Example 1.1 Spring-Mass-Damper Simulation


We can use LabVIEW to visualize the unforced time response of the mass displacement following an initial displacement of y(0).
Consider the underdamped case, where
√ 1
y(0) = 0.15 m, ωn = 2 rad/sec, ζ = √ , (k/M = 2, b/M = 1).
2 2

.
by ky
k
Wall
friction, b Mass y y
M M

r(t) r
Force

Figure 1.1: A mass-spring-damper system.


Figure 1.2: VI to analyze the spring-mass-damper.

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.

7.1 Bode Plots

Consider the transfer function


5(1 + 0.1s)
G(s) = . (7.1)
s(1 + 0.5s)(1 + 0.6
50 s + 1 2
502
s )

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).

You might also like