You are on page 1of 10

UNIVERSIDAD CATÓLICA SANTA MARÍA

FACULTAD DE CIENCIAS E INGENIERÍA FÍSICAS Y


FORMALES
PROGRAMA PROFESIONAL DE INGENIERÍA ELECTRÓNICA

Curso: Practicas Automatización Industrial


Grupo 1

Alumno:
Medrano Gálvez, Matías Alejandro
Siles Núñez, Liam Alexander

Tema: LabVIEW con MathScript

Semestre: IX
Arequipa – 2022
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


>>A=[1independent
Find the rank of a matrix. Provides an estimate of the number of linearly 2; 3 4] rows or columns of a matrix A.
rank >>rank(A)

Find the determinant of a square matrix >>A=[1 2; 3 4]


d >>det(A)
Find the inverse of a square matrix >>A=[1 2; 3 4]
inv >>inv(A)
Find the eigenvalues of a square matrix >>A=[1 2; 3 4]
e >>eig(A)
Creates an array or matrix with only ones >>ones(2)
ones >>ones(2,1)
>>eye(2)
eye Creates an identity matrix
Find the diagonal elements in a matrix >>A=[1 2; 3 4]
diag >>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)

[End of Example]

MathScript has lots of built-in functions for plotting:

Function Description Example


>X = [0:0.01:1];
plot Generates a plot. plot(y) plots the columns of y against
>Y = X.*X;
the indexes of the columns.
>plot(X, Y)
Create a new figure window >>figure
figu >>figure(1)

subplot Create subplots in a Figure. subplot(m,n,p) or subplot(mnp),


breaks the Figure window into an m-by-n matrix of small Add title to current plot title('string')
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 on” adds major grid lines to the current plot.
“grid off” removes major and minor grid lines from the
current plot.
axis Control axis scaling and appearance. “axis([xmin xmax ymin
ymax])” sets the limits for the x- and y-axis of the current
axes.
>>subplot(2,2,1) >>grid on
>>grid off

>>axis([xmin xmax ymin ymax])


>>axis off
>>grid >>axis on
>>title('this is a title')
Add xlabel to current plot >> xlabel('time')
xlabel
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 y¨(t) + b y˙(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 ω n1 − ζ 2 t + θ ,
1−
where θ = cos−1 ζ , ω2 = k/M and 2ζ ωn = b/M. The initial displacement is y(0) and y˙(0) = 0. The transient system response is
n
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

y(0) = 0.15 m, ωn √
2 , (k/M = 2, b/M = 1).
= 2 rad/sec, ζ=
1

by
. ky
Wall k
friction, b y M y
Ma
ss

r(t) r
Force

Figure 1.1: A mass-spring-damper syste


Simulacion y Grafica

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

Conclusiones:
 El módulo LabVIEW MathScript es un software adicional para el entorno de programación de LabVIEW que
incluye más de 750 funciones textuales integradas para procesamiento de señales, análisis y tareas matemáticas.
Proporciona una interfaz interactiva y programática.

 Puede implementar VIs que contengan Nodos de LabVIEW MathScript con funciones definidas por el usuario y
ciertas funciones de MathScript incorporadas a objetivos RT. Sin embargo, dependiendo de las funciones, los
tipos de datos y la sintaxis que utilice, LabVIEW podría ejecutar código en tiempo de ejecución que puede
provocar un aumento de la inestabilidad y tiempos de ejecución ilimitados en la aplicación en tiempo real.
Cuando el determinismo en la aplicación es importante, utilice las pautas de las siguientes secciones, que se
basan en las pruebas de National Instruments, para reducir la inestabilidad y lograr tiempos de ejecución
limitados para aplicaciones en tiempo real que contienen nodos de MathScript.

You might also like